Skip to content Skip to sidebar Skip to footer

Django Form Showing No Input Fields

I am getting a valid response back when requesting my form, but I am getting no form fields with the response. It is loading the Submit button only, but no form fields. Goal: get f

Solution 1:

You have two mistakes.

Firstly, you're passing the form class into the template context, not the form instance: the class is NewUserRegistrationForm, but you've instantiated it as NewUserRegForm, and that's what you should be passing as the value in the form context.

To make it more complicated, the key name you've given to that value is also NewUserRegistrationForm - but you're still referring to NewUserRegForm in the template, even though that doesn't exist there.

This would be much more obvious if you used PEP8 compliant names. Instances should be lower case with underscore: eg new_user_registration_form. However, in this case you could just call it form, since there's only one.

return render(request, 'mysite/reuse/register.html', {
    'NewUserRegForm': NewUserRegForm 
})

or, better:

form = NewUserRegistrationForm(request.POST or None)
...
return render(request, 'mysite/reuse/register.html', {
    'form': form 
})

Solution 2:

You're passing the form instance to the context as 'form', but calling it in the template as {{ NewUserRegForm.as_p }}.

You should use {{ form.as_p }} instead.

Post a Comment for "Django Form Showing No Input Fields"