为了让我的问题更清楚,这里有一个小应用程序,它将一个句子输入并输出两次。在
我有base.html
:
<html>
<head>
<title> My site </title>
<body>
{% block content %}{% endblock %}
</body>
</html>
和index.html
:
以下是views.py
的一部分:
from forms import DoublerForm
@app.route('/index')
def index():
form = DoublerForm()
if form.validate_on_submit():
s = form.sentence.data
return render_template('index.html', form=form, s=str(s) + str(s))
return render_template('index.html', form=form, s="")
这里是forms.py
,不包括所有进口:
class DoublerForm(Form):
sentence = StringField(u'Text')
这似乎行得通。但是我希望我的输入表单在base.html
模板中,这样它就可以显示在扩展它的所有页面上,而不仅仅是index
页面。如何将窗体移动到基本.html并为所有扩展的视图实例化窗体base.html?在
You can use the flask.g object and ^{}.
也可以显式定义上下文函数
^{pr2}$是这样用的
现在,您可以在所有解压上下文字典的模板中找到添加到上下文字典的对象。在
在索引.html在
在基本.html在
相关问题 更多 >
编程相关推荐