图像单选按钮_

2024-06-28 16:17:47 发布

您现在位置:Python中文网/ 问答频道 /正文

尝试找出如何使用图像作为单选按钮,使用flask_wtf作为表单中的Radiofield类型的问题。我不知道你是怎么把图像设置成单选按钮的。你知道吗

我知道如何只使用普通的html而不使用flask_wtf来实现这一点。我的窗体设置和flask_wtf类都正确。我知道我必须以类似的方式在问题的子字段中循环:

{% for subfield in form.question1 %}
<tr>
<td>{{ subfield }}</td>
<td>{{ subfield.label }}</td> <!-- but how to set image??-->
</tr>
{% endfor %}

这是flask_wtf类。为了演示,它只有一个问题:

class questionform1(FlaskForm):
    question1 = RadioField('Question1', choices = [('a','a'),('b','b'), ('c','c'),('d','d')])

如果只使用HTML,我会这样做:

<label>
<input type="radio" name="q1" value="a" id="q1a" required><img 
src="/static/img/image1.png">
</label>

我相信这是有可能的,但网上缺乏关于如何做的信息,有什么建议吗?你知道吗


Tags: 图像flask表单类型imghtml窗体按钮