这是我的代码,test.html
if
声明中有问题。你能帮我修改if
条件,test.html
因为我可以通过选择字段值获得不同的 UI 元素吗?
表格.py
class testForm(forms.Form):
runtype = forms.ChoiceField(choices=[(0, 0), (1, 1)])
byname = forms.CharField()
byindex = forms.IntegerField()
视图.py
@csrf_exempt
def osys(request):
if request.method == 'POST':
form = testForm(request.POST, request.FILES)
if form.is_valid():
runtype = form.cleaned_data['runtype']
if runtype == 0:
byname = form.cleaned_data['byname']
if runtype == 1:
byindex = form.cleaned_data['byindex']
print byname, byindex, runtype, filename
return HttpResponse('OK')
else:
form = testForm()
return render_to_response('test.html', locals())
测试.html
<form method="post" >
{{form.runtype}}
{% if form.runtype ==0 %}
{{form.byname}}
{% if form.runtype ==1 %}
{{form.byindex}}
<input type="submit" value="Start Run" name="btnRun"></input>
</form>