我正在使用相同的表格并更改选择。
所有选项都有翻译。
我需要在表格中指定一些内容吗?
表格.py
class QuestionForm(forms.Form):
selection = forms.ChoiceField(widget=forms.RadioSelect())
视图.py
from django.utils.translation import ugettext as _
form = QuestionForm(request.POST)
choices = [(_(i.choice), i.choice) for i in question.choices.all()]
form.fields['selection'].choices = choices
模板
<form method="post">{% csrf_token %}
{{ form.selection }}
<input type="submit" value="Submit" class="btn"/>
</form>
我试过
{% trans form.selection %}
但得到了错误”
'BoundField' object has no attribute 'replace'