我有一个带有单个文本输入字段的简单表单,它没有显示在模板中。仅显示表单的提交按钮。
模板:
<form method='POST' action="example">
{{ form.as_p }}
<input type="submit" value="submit"/>
</form>
表格:
class sampleform(forms.Form):
data = forms.CharField(label = u'Add a text:')
风景:
def example(request):
if request.method == 'POST':
form = sampleform(request.POST)
if form.is_valid:
return HttpResponseRedirect('/register/success/')
else:
form = sampleform()
variables = RequestContext(request,{'form':form})
return render_to_response('stream.html',variables)