0

刚接触 Django,我有一个名为曝光的应用程序:

我有一个表格:

usersegment = [['adminLevel0','Admin Level 0'],['adminLevel1','Admin Level 1'], ['adminLevel2','Admin Level 2']]

class ExposureForm(forms.Form):
    adminLevel = forms.ChoiceField(widget=forms.RadioSelect(), choices=usersegment)

我有一个看法:

def exposure_form(request):
        if request.method =='GET':
                form = ExposureForm()
                return render_to_response('exposure-export-wizard.html')
        else:
                html = '<html><body>Your request cannot be processed</body></html>'
                return HttpResponse(html)

我有模板(不工作):

<form action="/exposure_form/" method="get">{% csrf_token %}
{{ form.as_p }}

问题是如何从模板访问我的单选按钮?

4

1 回答 1

1

您需要将模板渲染到上下文

def exposure_form(request):
    if request.method =='GET':
        form = ExposureForm()
        return render_to_response('exposure-export-wizard.html', {'form': form}, context_instance=RequestContext(request)))

更多文档在这里

于 2013-05-03T16:12:37.150 回答