Flask is one the famous (micro) web framework in Python. Its built with a small core and has a philosophy easy-to-extend. Its also provide easy to learn and simple to use, it will help you develop web applications easiest.
Install Flask
Before we go deep dive in Flask, we need prepare Virtual Environment. Virtual Environment help a lot in managing dependencies in Python, especially when we have many project using Python with some of them with different Python version. If you already using Python 3.x then no need to install Virtual Environment since in Python 3.x come with venv as their standard library. But if you are still Python 2.x user, then you need to install Virtual Environment and here the step :
Install Virtual Environment
In Linux package Virtual Environment already provided by the Package Manager
// Debian/ Ubuntu Distro
$ sudo apt-get install python-virtualenv
// Fedora/ CentOS Distro
$ sudo yum install python-virtualenv
// ArchLinux Distro
$ sudo pacman -S python-virtualenv
If you are OS X user the need to install pip first since easy_install is deprecated. Please use get-pip.py instead.
$ curl https://bootstrap.pypa.io/get-pip.py | python2
$ python2 -m pip install virtualenv
Setup Virtual Environment
Create project folder and a venv within.
Install Flask
Use this command to install Flask.
$ pip install flask
Project Structure
Flask application can be a simple with just one single file.
// hello.py
from flask import Flask
app = Flask(__name__)@app.route('/')
def hello():
return 'Hello, world!'
but in the meantime project can be more bigger then project structure could be like this.
/flask-example
|-- app
| |-- static
| | |-- css
| | |-- js
| | |-- img
| |-- templates
| |-- routes.py
|-- venv
|-- README.md
The project directory could be contain :
app/
a python package that contain all your project filesstatic
/ contain all web app content likecss
,js
andimages
venv/
a Python virtual environment where Flask and other dependencies are installed
This post can be found in here link.