реализация флажка в flask_wtf, выдающего ошибку значения - PullRequest
0 голосов
/ 05 августа 2020

Я новичок в flask и пытаюсь установить флажок с помощью flask_wtf. index. html

<body>
{{ form.permission }}
</body>

form_validator.py

class MultiCheckboxField(SelectMultipleField):
    widget = widgets.ListWidget(prefix_label=False)
    option_widget = widgets.CheckboxInput()


class SimpleForm(FlaskForm):
    permission = MultiCheckboxField('Label', choices=[('1','1'),('2','2')])

Я получаю эту ошибку на веб-странице

File "/root/plugins/create_job/app_builder.py", line 38, in list
    return self.render_template("index.html", form=form)
  File "/usr/local/lib/python3.7/site-packages/flask_appbuilder/baseviews.py", line 281, in render_template
    template, **dict(list(kwargs.items()) + list(self.extra_args.items()))
  File "/usr/local/lib/python3.7/site-packages/flask/templating.py", line 140, in render_template
    ctx.app,
  File "/usr/local/lib/python3.7/site-packages/flask/templating.py", line 120, in _render
    rv = template.render(context)
  File "/usr/local/lib/python3.7/site-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "/root/plugins/create_job/templates/index.html", line 2, in top-level template code
    {{ form.permission }}
  File "/usr/local/lib/python3.7/site-packages/wtforms/fields/core.py", line 144, in __html__
    return self()
  File "/usr/local/lib/python3.7/site-packages/wtforms/fields/core.py", line 160, in __call__
    return self.meta.render_field(self, kwargs)
  File "/usr/local/lib/python3.7/site-packages/wtforms/meta.py", line 56, in render_field
    return field.widget(field, **render_kw)
  File "/usr/local/lib/python3.7/site-packages/wtforms/widgets/core.py", line 300, in __call__
    for val, label, selected in field.iter_choices():
  File "/usr/local/lib/python3.7/site-packages/wtforms/fields/core.py", line 525, in iter_choices
    for value, label in self.choices:
ValueError: not enough values to unpack (expected 2, got 0)

Я отладил журнал, но не смог ' Я нашел для этого причину. Есть ли другой способ реализовать флажок в wtform

...