大家好,使用 WTForms中的SelectMultipleField构建了一个复选框,但显示有问题,如下图
可管理栏目都挤到一起了,怎么才能分开呢?代码如下:
Forms.py
access_category = SelectMultipleField( # 可访问的类别
label=“可管理栏目”,
# widget=widgets.ListWidget(prefix_label=False),# prefix_label复选框的位置
widget=widgets.TableWidget(with_table_tag=False),
option_widget=widgets.CheckboxInput(),
coerce=int,
default=[1, 2]
)
def init(self, *args, **kwargs):
super(Reg_user_Form, self).init(*args, **kwargs)
self.access.choices = [(1, ‘文章管理员’), (2, ‘超级管理员’)]
self.access_category.choices = [(Category.id, Category.name)
for Category in Category.query.order_by(Category.id).all()]
模板渲染代码
{% extends ‘base.html’ %}
{% from ‘bootstrap/form.html’ import render_form %}
{% block title %}注册用户{% endblock %}
{% block content %}
<div class="page-header">
<h1>注册用户信息</h1>
</div>
{{ render_form(form) }}
{% endblock %}