Flask Tutorial - Learn to code in Flask | AppSeed
MIT License
Content provided by experienced developers based on the suggestions/questions from the audience. This initiative aims to provide Free/Allways up-to-date programming tutorials - Read the Manifest.
AppSeed
team👉 Flask is a lightweight web application framework. It is designed to make getting started quick and easy, with the ability to scale up to complex applications. Compared to Django, Flask provides a lightweight codebase and more freedom to the developer.
👉 The easiest way to install Flask is to use PIP the official package-management tool.
$ pip install Flask
How to check Flask version
Open a Python console (type python in terminal) and check the installed version as below:
>> import flask
>> flask.__version__
'1.1.2'
>>>
In this case the installed version is 1.1.2
👉 Open a terminal and install Flask (if not already installed) using PIP:
$ pip install Flask
Use your preferred editor to create a file called hello.py with this content:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return f'My first Flask!'
Save the file and start the app:
$ env FLASK_APP=hello.py flask run
* Serving Flask app "hello"
* Running on http://127.0.0.1:5000/
Above commnand does two things:
FLASK_APP
variable (required by Flask)flask run
commandBy visiting the app in the browser localhost:5000 we should see My first Flask! message.
👉 Being such a lightweight framework, Flask comes with great flexibility regarding the codebase structure of a project. We can use a single file and drop all the code or split the app logic in more files and directories. All variants works but we migth have issues once our project is getting bigger and migth become unreadable for others.
Well, this section presents a few options to keep in mind when we start a Flask project.
🔗 Read more: Flask Project Structure: Single File, Isolated App, Blueprints
👉 We can use the information learned in the previous sections and build from scratch a simple Flask project on top of a modern Bootstrap UI Kit.
🔗 Read more: Flask Bootstrap Sample
👉 Jinja is a modern and designer-friendly templating language for Python, modelled after Django's templates. It is a text-based template language and thus can be used to generate any markup as well as source code.
🔗 Read more: Jinja Template
Flask Tutorial - Free/Allways up-to-date Flask-related content | by AppSeed.