Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
python:flask:blueprints [2020/12/12 15:01] marclebrun |
python:flask:blueprints [2021/08/29 06:25] (Version actuelle) marclebrun [Organiser l'application grâce aux Blueprints] |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ====== Blueprints ====== | + | ====== Organiser l'application grâce aux Blueprints ====== |
+ | |||
+ | Tutorial : [[https://www.youtube.com/watch?v=wC3qkE5vD4M]] | ||
+ | |||
+ | <code> | ||
+ | /home/marc/flaskapp | ||
+ | ├── app | ||
+ | │ ├── section1 | ||
+ | │ │ ├── __init__.py | ||
+ | │ │ └── ... | ||
+ | │ │ | ||
+ | │ ├── section2 | ||
+ | │ │ ├── __init__.py | ||
+ | │ │ └── ... | ||
+ | │ │ | ||
+ | │ ├── templates | ||
+ | │ │ ├── section1 | ||
+ | │ │ │ ├── home.html | ||
+ | │ │ │ └── ... | ||
+ | │ │ │ | ||
+ | │ │ ├── section2 | ||
+ | │ │ │ ├── home.html | ||
+ | │ │ │ └── ... | ||
+ | │ │ │ | ||
+ | │ │ └── base.html | ||
+ | │ │ | ||
+ | │ ├── __init__.py | ||
+ | │ ├── ... | ||
+ | │ ├── home.py | ||
+ | │ └── ... | ||
+ | ├── run.py | ||
+ | └── ... | ||
+ | </code> | ||
===== home ===== | ===== home ===== | ||
- | <code python home.py> | + | <code python app/home.py> |
from flask import Blueprint, render_template | from flask import Blueprint, render_template | ||
Ligne 15: | Ligne 47: | ||
===== __init__.py ===== | ===== __init__.py ===== | ||
- | <code python __init__.py> | + | <code python app/__init__.py> |
- | from flask import Flask, render_template | + | from flask import Flask |
+ | from app.home import home | ||
app = Flask(__name__) | app = Flask(__name__) | ||
+ | app.register_blueprint(home) | ||
+ | </code> | ||
+ | |||
+ | ===== run.py ===== | ||
- | if __name__ == '__main__': | + | <code python run.py> |
- | app.run(debug=True) | + | from app import app |
+ | app.run(host="0.0.0.0", port=8000, debug=True) | ||
</code> | </code> | ||