我有以下情况:
表单.py
REASONS = [
{'code': 1, 'reason': 'I want to unsubscribe'},
{'code': 2, 'reason': 'I hate this site'}]
Myform(forms.Form):
magic_field = forms.CharField(required=True)
def __init__(self):
# Depending on the REASONS list add the fields to the form
for key in REASONS:
self.fields['reason_{}'.format(key['code'])] = forms.BooleanField(
label=_(key['reason']),
widget=widgets.CheckboxInput())
我想要的是把原因按随机顺序排列。在
模板.html
^{pr2}$
为什么不先把原因混在一起,然后在模板中使用
{% for %}
循环呢?在比如:
希望这有帮助
编辑 你可以创建一个过滤器或者一个函数,比如
^{pr2}$在你的助手.py比如:(我不知道到底是怎么做到的)
嗯,现在我看到了,你可以直接在模板中这样做,因为你使用的是jinja2
相关问题 更多 >
编程相关推荐