我是 Django 的新手。现在我在下面定义了类
PROPERTY_TYPE_CHOICE = [['1', 'Fixed (TODO)'],
['2', 'Trajectory (TODO)'],
['3', 'Error_Detecting'],
['4', 'Error_Correcting']]
FIXED_TYPE_CHOICE = [['1', 'Prefix',
'2', 'Suffix']]
class UploadFileForm(forms.Form):
# title = forms.CharField(max_length=50)
automata_file = forms.FileField(required = True)
transducer_file = forms.FileField(required = True)
property_type = forms.ChoiceField(choices=PROPERTY_TYPE_CHOICE,
required=True)
fixed_type = forms.ChoiceField(choices=FIXED_TYPE_CHOICE,
required=True)
debug_output = forms.BooleanField(required=False)
我在前面的 html 中显示了这个 PROPERTY_TYPE_CHOICE
<div class="fieldWrapper">
{{ form.property_type.errors }}
<label for="id_a">Select <u>a type</u> of property:</label>
{{ form.property_type }}
</div>
如果我在 PROPERTY_TYPE_CHOICE 中选择第一个选项“Fixed (TODO)”,我想显示 FIXED_TYPE_CHOICE。我阅读了有关 Django 的文档,我认为它可能以这种方式实现:
<div class="fieldWrapper">
{{ form.property_type.errors }}
<label for="id_a">Select <u>a type</u> of property:</label>
{{ form.property_type }}
</div>
{% if form.property_type=='1' %}
<div class="fieldWrapper">
{{ form.fixed_type.errors }}
<label for="id_a">Select <u>a fixed type</u> of property:</label>
{ { form.fixed_type }}
</div>
{% endif %}
但我不能那样做。我应该怎么办?谢谢你。