Python Flask Introduction














































Python Flask Introduction



INTRODUCTION TO FLASK

Flask is a lightweight, WSGI web application framework. It was designed to make getting started quick and easy, with the ability to scale up to complex applications. It began as a simple wrapper around Werkzeug and Jinja and has become one of the most popular Python web application frameworks. 

Create an environment

Create a project folder and a venv folder within:

$ mkdir myproject
$ cd myproject

On Lunix

$ python -m venv venv

On Windows:

$ py -3 -m venv venv 

Activate the environment

On Lunix

$ . venv/bin/activate

On Windows:

$ venvScriptsactivate 


Install  Flask into the virtual environment

Install and update using pip:

$ pip install -U Flask

Installing using github:

$ pip install -U https://github.com/pallets/flask/archive/master.tar.gz


A Simple Example

from flask import Flask
app = Flask(__name__)

app = Flask(__name__)
@app.route("/")
def hello():
return "Hello, World!"

Running the Application

On Windows

set FLASK_APP=hello
run flask

Output

The default hosted address if 127.0.0.1(localhost) and the default port is 5000


Next: Flask Basic Application structure


Comments