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:conception_par_modules [2023/09/29 07:12] marclebrun |
python:flask:conception_par_modules [2023/10/02 09:15] (Version actuelle) marclebrun [Arboresence] |
||
---|---|---|---|
Ligne 35: | Ligne 35: | ||
/templates # templates du module | /templates # templates du module | ||
users.py # code du module | users.py # code du module | ||
+ | | ||
+ | /static # assets de base de l'application | ||
+ | /bootstap | ||
+ | /chartjs | ||
+ | /css | ||
+ | styles.css | ||
+ | /img | ||
+ | /js | ||
| | ||
/templates # templates de base de l'application | /templates # templates de base de l'application | ||
Ligne 79: | Ligne 87: | ||
</body> | </body> | ||
</html> | </html> | ||
+ | </code> | ||
+ | |||
+ | ===== Module "Main" ===== | ||
+ | |||
+ | ==== /app/modules/main/main.py ==== | ||
+ | |||
+ | <code python> | ||
+ | from flask import Blueprint | ||
+ | from flask import render_template | ||
+ | |||
+ | main = Blueprint("main", __name__, | ||
+ | static_folder="static", | ||
+ | template_folder="templates" | ||
+ | ) | ||
+ | |||
+ | @main.route("/", methods=['GET']) | ||
+ | def home(): | ||
+ | return render_template("main.home.html.j2") | ||
+ | </code> | ||
+ | |||
+ | ==== /app/modules/main/templates/main.home.html.j2 ==== | ||
+ | |||
+ | <code twig> | ||
+ | {% extends 'base.html.j2' %} | ||
+ | |||
+ | {% block content %} | ||
+ | <p>Module main : home</p> | ||
+ | {% endblock %} | ||
+ | </code> | ||
+ | |||
+ | ===== Module "Articles" ===== | ||
+ | |||
+ | ==== /app/modules/articles/articles.py ==== | ||
+ | |||
+ | <code python> | ||
+ | from flask import Blueprint | ||
+ | from flask import render_template | ||
+ | |||
+ | articles = Blueprint("articles", __name__, | ||
+ | static_folder="static", | ||
+ | template_folder="templates" | ||
+ | ) | ||
+ | |||
+ | @articles.route("/", methods=['GET']) | ||
+ | def home(): | ||
+ | return render_template("articles.home.html.j2") | ||
+ | </code> | ||
+ | |||
+ | ==== /app/modules/articles/templates/articles.home.html.j2 ==== | ||
+ | |||
+ | <code twig> | ||
+ | {% extends 'base.html.j2' %} | ||
+ | |||
+ | {% block content %} | ||
+ | <p>Module articles : home</p> | ||
+ | {% endblock %} | ||
</code> | </code> | ||