[英]ModelForm Not Showing in Template
For some reason (excuse my newbieness with django) my template is not displaying my form, I currently have: 由于某种原因(对django的求婚),我的模板没有显示我的表单,我目前有:
view 视图
def Scan(request):
form = SubmitDomain(request.POST or None) # A form bound to the POST data
if request.method == 'POST': # If the form has been submitted...
if form.is_valid(): # If form input passes initial validation...
form.cleaned_data['domainNm'] ## clean data in dictionary
form.save()
return HttpResponseRedirect('/processing/')
else:
form = SubmitDomain()
return render(request, 'VA/index.html', {
'form' : 'form'
})
I read on here to use {{ form.as_p }}
to display the <input>
of the form, but it isn't showing. 我在这里阅读了使用{{ form.as_p }}
来显示表单的<input>
的方法,但是没有显示。 Is something glaringly preventing this? 有什么明显的预防措施吗?
The problem is that you are passing an string
as form
not the instance
of SubmitDomain
change this: 问题是您要以string
form
传递而不是SubmitDomain
instance
更改此形式:
return render(request, 'VA/index.html', {
'form' : 'form'
})
for this: 为了这:
return render(request, 'VA/index.html', {
'form' : form
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.