【发布时间】:2020-10-24 20:22:50
【问题描述】:
我正在尝试使用 UIkit 设置我的 WTForm Radio 输入的样式,但是在遍历每个字段时,我无法弄清楚如何应用该类。如果我将form.difficulty(class_"uk-radio") 添加到for 循环中,我会得到一个疯狂的输出而不是格式化的字段。将此 UIkit 类应用于 WTForm 中的 radio 字段的正确语法是什么?
谢谢!
HTML:
{% from "_formhelpers.html" import render_field %}
<form class="uk-grid-small uk-background-muted uk-padding" action="/ask/" method="post" uk-grid>
<div class="uk-width-1-2@s uk-margin-small">{{ render_field(form.title,placeholder="The Problem", class_="uk-input") }}</div><br>
<div class="uk-width-1-1 uk-margin-small">
<strong>Question Difficulty:</strong>
<br>
{% for subfield in form.difficulty(class_="uk-radio") %}
<tr>
<td>{{ subfield.label }}</td>
<td>{{ subfield }}</td>
</tr>
{% endfor %}
</div>
<br>
<div class="uk-width-1-1 uk-margin-small">
{{ render_field(form.body,placeholder="My device probably has a virus. I clicked the wrong link, and I have like a million popups a minute now. Minute.tech HELP! I need some direction here guys.", class_="uk-textarea", rows="20", cols="100") }}
</div>
<br>
<div class="uk-width-1-1 uk-margin-small">{{ render_field(form.tags,placeholder="Mac, virus, Facebook, etc", class_="uk-input") }}</div>
<br>
<div class="uk-width-1-4@s uk-margin-small">
<input class="uk-button uk-button-primary" type="submit" value="Ask">
</div>
</form>
Python
class AskForm(Form):
difficulty = RadioField('Difficulty Rating', choices = [('1','1'), ('2','2'),('3','3'),('4','4'),('5','5')])
title = TextField('Title:', [validators.Length(min=5, max=100)])
body = TextAreaField('Desciption:', [validators.Length(min=10, max=2000)])
tags = TextField('Tags:', [validators.Optional()])
结果:
编辑:
试过{{ render_field(form.difficulty, class_="uk-input") }},输出仍然是垂直格式而不是样式
结果:
【问题讨论】:
标签: flask uikit jinja2 wtforms