0

这是我的代码,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>
4

1 回答 1

0

Django 模板在服务器端呈现为纯 HTML,然后发送到不知道模板代码的客户端。

如果您需要在客户端动态执行操作,则需要使用 JavaScript。

于 2015-05-03T09:14:15.317 回答