本文介绍了分配css类以形成从flask传递到jinja的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对Jinja/flask很陌生,正在我的flask应用程序中创建动态表单:
I am quite new to jinja / flask, I am creating dymnamic form in my flask app:
class CreateForm(FlaskForm):
searchCity = StringField('View forcast of city:', validators=[InputRequired("Please enter the city you want to check weather updates")])
count = IntegerField("Days")
submit = SubmitField("Submit")
form = CreateForm(request.form)
form.count.default = count
form.count.label = "Days" if count > 1 else "Day"
form.count.data = count
和在jinja模板中:
and in jinja template:
<form>
<dl>
<dd>{{ form.searchCity.label }} {{ form.searchCity(size=20) }}
for next {{ form.count(size=2) }} {{ form.count.label }}
<input type="submit" class="btn-primary" value="Submit" id="calculate" onclick="getWeatherForcaset(
document.getElementsByName('searchCity')[whole_number].value,
document.getElementsByName('count')[whole_number].value
);" >
</dd>
<dd>
<input type="checkbox" name="exactMatch" checked="checked">Exact Match
<input type="checkbox" name="remember">Remember<br/ >
</dd>
</dl>
</form>
我想将类form-group
分配给searchCity
输入框!任何帮助将不胜感激,谢谢
I want to assign class form-group
to searchCity
inputbox !any help would be greatly appreciated thanks
推荐答案
您应该能够像这样将变量传递到构造函数中
You should be able to pass variables into the constructor like so
{{ form.searchCity(size=20, class_='searchCity') }}
可在以下位置找到文档:
Documentation is available at :
http://wtforms.readthedocs.io/en/latest /crash_course.html#rendering-fields
文档片段
form.content(style ="width:200px;",class _ ="bar")
form.content(style="width: 200px;", class_="bar")
<input class="bar" id="content" name="content" style="width: 200px;" type="text" value="foobar" />'
这篇关于分配css类以形成从flask传递到jinja的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!