默认情况下,Flask 使用存储在“template”目录中的模板文件:
/flaskapp
/application.py
/templates
/hello.html
有没有办法根据登录的用户动态选择模板目录?这就是我想要的目录结构:
/flaskapp
/application.py
/templates (default template goes here)
/hello.html
/userdata
/user1
/template1
hello.html
/template2
hello.html
/user2
/template1
hello.html
/template2
hello.html
现在,如果我有登录用户的用户名和用户激活的模板名称,是否可以动态选择加载模板文件的目录?例如,
/userdata/<username>/<activated template name>/
而不是固定的
/templates/
我想要实现的是我的网络应用程序的类似 WordPress 的主题系统,用户可以在其中上传/选择他的网站的主题。
您可以向 Flask 构造函数传递一个“template_folder”参数。
就像这样...
Flask(__name__, template_folder="wherever")
这是文档:http://flask.pocoo.org/docs/api/ http://flask.pocoo.org/docs/api/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)