Hey, welcome back.
Let's start building our Flask application form app.
So let's jump into PyCharm and create a new project.
So you want to go to file New project.
So I'm going to put this inside users as which is an existing directory and then app 16 flask form.
This will be created.
This directory will be created.
I'm leaving the other parameters as they are and press on create.
So there we go.
And a Flask app has this structure.
It has a templates directory.
And a static directory.
So please name them.
As you see here, the names of these folders are very important.
So static with lowercase letters, templates with lowercase letters.
And then we also create a new python file which usually has the name app dot pi or main dot pi.
Either way, it's fine.
Then inside templates you want to create a new HTML file.
And name it index.html.
The name can be different, but please use the same name as me because this name then will be referred
from the app.py file.
So in the python code we will be sending this HTML code to the front end to the web page here.
So this web page is built using HTML and that HTML code will go inside index.html.
So press enter.
PyCharm will add some sample html.
I'll just select this and delete it.
So that's what we have two empty files and that's the directory structure of a flask app.
So we have static templates.
And app.py inside static.
You may want to put files such as images.
For example, if your app has some images, your website or your web application contains images, you
put those images inside that static folder, or if your website has some CSS codes or some JavaScript
code, you put those CSS files and JavaScript files inside the static folder.
As a start.
Let's add some code in the app.py file.
So we want to import from Flask import the Flask class.
Now flask is not installed yet, so you want to hover your mouse here and go to install package flask.
So that will install flask in my virtual environment.
You see, I have this venv here.
When I created the PyCharm project, PyCharm created this virtual environment That's good to have.
And then we want to create an app instance using that FLASK class.
And this gets as arguments, the underscore, underscore, name, underscore, underscore and then we
say app dot run debug equal to true port equal to 5001.
For example.
You can put anything here.
If we run this, let's try to run it.
So right click and run app.
You should see this message normally.
So that means this is working and you can access the app at this URL.
So you can click that URL to open it with your default browser or you can copy it, copy the URL and
go to your preferred browser.
Or you can right click here and perhaps PyCharm will show this context menu here.
So you can go to open in Chrome and you should see this normally not found for now.
So the app is working.
You didn't get something like, Oh, there is nothing here.
So if we quit this app.
So stop it with that red button.
Now it says process finished.
Now if you go to your browser reload that you'll see this site can't be reached.
So this is a different error from that one.
So the other error, which is when we run the app.
So it's running now.
This is not found, which means this particular page, the home page was not found.
And similarly, you will get something else.
For example, if you go to my page, slash my page, you again will get not found.
So the app is working, but these pages have not been implemented yet and that's what we want to do
next.
So in between these two lines here, we are going to handle requests, URL requests, or technically
known as HTTP requests.
So when you load the page one web page with your enter key in your browser, you are making an HTTP
request.
So that's what flask is for.
Flask can handle those requests.
So with Python, you receive those requests and then you allocate that request to a particular HTML
page, right?
So if the user is visiting the home page, which is this one here.
Then with some python codes here, we will say, Oh, get that home page and then show that index.html
page here on the website.
Right.
And similarly, when the user goes to my page, then we'll send something else.
We'll have another HTML file here, my page dot HTML and we will render that in the website.
So that's how Flask works.
So what we'll do next is we will populate this area here with code so that we can handle those HTTP
requests.
I'll see you in the next video.