Flask
Flask is a lightweight Web application framework written in Python.
Install
1 | pip install flask |
Structure
Flask is very flexible, it has no certain pattern of a project folder structure.
Functional Based Structure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18project
├── __init__.py
├─models
| ├── base.py
| ├── users.py
| ├── posts.py
| └── __init__.py
├─routes
| ├── home.py
| ├── account.py
| └── __init__.py
├─templates
| ├── base.html
| └── post.html
├─services
| ├── google.py
| ├── mail.py
| └── __init__.pyApp Based Structure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17project
├── db.py
├── main.py
├── __init__.py
├── source
├─auth
| ├── models.py
| ├── route.py
| ├── templates.py
| └── __init__.py
├─blog
| ├── models.py
| ├── route.py
| ├── templates.py
| └── __init__.py
pip freeze > requirements.txt
pip install -r requirements.txt
Connect MySQL
1 | # setting.py Some configurations for connecting to the database |
Issue
ImportError: No module named flask.ext.sqlalchemy
1
2
3pip install flask-sqlalchemy
from flask_sqlalchemy import SQLAlchemyThe query results convert to JSON
Requirement
1 | pip freeze > requirements.txt |