Getting start with Flask
Flask is a favorite library for web application development in Python. It is simple, light weight and fast growing library and privides extensive area in web application development. If you want to know more about Flask please read the documentation from here Flask
Prerequisite
- Python installed in your machine
- PIP installed in your machine
Note:
I am using MacOS. If you use windows then some command might be change
Lets start..
Make a new directory
Make a directory to install Flask app
Create virtual environment for our project
To create virtual environment please execute this command
Activate virtual env
Install Flask
Create an python file to write our first route for App
Initialize the Flask App
Write folling code in app.py
file.
Congratulation!! We have created our first route. Now If we can run our local server then We can see our app.
Run the Flask App
To run the app we need to export the app.py
Please execute following commands serially
If everything is fine then a local server will start in http://127.0.0.1:5000
address. If we browse this in our browser then we can see our text “This is Home page”
Congratulation!! You have successfully install and run the Flask App.
Note:
If you want to deactivate the virtual env then simply type deactivate
.
Happy Coding :)