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 }}
问题是如何从模板中访问我的单选按钮?
答案 0 :(得分: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)))
更多文档here。