Flask – Environment
To install flask on the system, we need to have python 2.7 or higher installed on our system. However, we suggest using python 3 for the development in the flask.
Install Virtual Environment
virtualenv
is a virtual python environment builder. It helps a user to create multiple python environments side-by-side.
pip install virtualenv
Once it is installed, we can create the new virtual environment into a folder as given below.
mkdir my_flask_project cd my_flask_project virtualenv venv
Activate the Virtual Environment
To activate the virtual environment the commands differ based on your operating system:
pip install virtualenv
Simple Web Page
app.py
from flask import Flask app = Flask(__name__) @app.route("/") def index(): return "<h1>Welcome to Flask</h1>" if __name__=='__main__': app.run()
Run the Project:
- Run 'app.py' file.
- Browse the URL 'localhost:5000'.
Output:
![Simple Web Page using Flask](images/index-flask-outpt.png)