flask blueprint template folder

后端 未结 5 1990
傲寒
傲寒 2020-11-30 18:32

My flask app layout is:

myapp/
    run.py
    admin/
        __init__.py
        views.py
        pages/
            index.html
    main/
        __init__.py         


        
5条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 19:19

    twooster's answer is interesting, but another problem is that Jinja by default caches a template based on its name. Because both templates are named "index.html", the loader won't run for subsequent blueprints.

    Besides linqq's two suggestions, a third option is to ignore the blueprint's templates_folder option all together and place the templates in respective folders in the application's templates directory.

    ie:

    myapp/templates/admin/index.html
    myapp/templates/main/index.html
    

提交回复
热议问题