1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Flask per-application template folder

Discussão em 'Python' iniciado por Stack, Setembro 15, 2024.

  1. Stack

    Stack Membro Participativo

    I implementing simple site with couple of applications (like blog, code, account, etc). I decided to split one python file to apps due to large size. I do not using blueprints or something else except basic functionality of Flask - I'd like to keep it as simple as it possible. Unfortunately, flask still looking for templates in the

    /site
    |-> main.py
    from flask import Flask

    app = Flask(__name__)
    app.config.from_pyfile('config.py')

    # Import all views
    from errors.views import * # Errors hasn't its specific prefix
    from blog.views import *
    from account.views import *
    from mysite.views import *

    if __name__ == "__main__":
    app.run(debug=True)
    |-> templates
    ...................
    |->blog
    |-> template
    |-> _layout.html
    |-> index.html
    |-> post.html
    |-> __init__.py
    from main import app
    import blog.views
    |-> views
    from blog import app
    from flask import render_template

    @app.route("/blog/", defaults={'post_id': None})
    @app.route("/blog/<int:post_id>")
    def blog_view(post_id):
    if post_id:
    return "Someday beautiful post will be here with id=%s" % post_id
    else:
    return "Someday beautiful blog will be here"

    @app.route("/blog/tags/")
    def tags_view():
    pass
    ..........................

    Continue reading...

Compartilhe esta Página