我有几个不同的模板,我正在尝试用于我的烧瓶应用程序.
我尝试过以下但它似乎只是直接在/ templates内部而不是/ templates/folder1,templates/folder2等.
return render_template('index.html', template_folder='folder1')
return render_template('folder1/index.html')
Run Code Online (Sandbox Code Playgroud)
两者都没有按预期工作,我如何指定不同模板的子文件夹.
naa*_*man 11
创建Flask应用程序(或蓝图)时可以指定模板文件夹:
from flask import Flask
app = Flask(__name__, template_folder='folder1')
Run Code Online (Sandbox Code Playgroud)
资料来源:http://flask.pocoo.org/docs/0.12/api/#application-object
from flask import Blueprint
auth_blueprint = Blueprint('auth', __name__, template_folder='folder1')
Run Code Online (Sandbox Code Playgroud)
资料来源:http://flask.pocoo.org/docs/0.12/blueprints/#templates
这template_folder是相对于app/blueprint所在的位置.使用该os库创建app/blueprint目录之外的模板文件夹的路径.
例如.
import os
APP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_PATH = os.path.join(APP_PATH, 'templates/')
Run Code Online (Sandbox Code Playgroud)
小智 -14
我认为肖恩是对的,但同时:你尝试过双引号吗?我使用的是蓝图,所以它可能会有所不同,但这就是我的样子:
return render_template("users/register.html")
Run Code Online (Sandbox Code Playgroud)
所以你的可能是:
return render_template("folder1/index.html")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13789 次 |
| 最近记录: |