ModelForm不显示在模板中

时间:2013-08-01 00:27:59

标签: django django-templates django-forms

出于某种原因(借口django我的新手)我的模板没有显示我的表格,我目前有:

查看

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'
    })

我在here上看到要使用{{ form.as_p }}来显示表单的<input>,但它没有显示。是否明显阻止了这一点?

1 个答案:

答案 0 :(得分:1)

问题是您传递string form而不是instance SubmitDomain 改变这个:

 return render(request, 'VA/index.html', {
    'form' : 'form'
})

为此:

 return render(request, 'VA/index.html', {
        'form' : form
    })