stillwater
stillwater

Reputation: 47

Global name 'RegistrationForm' is not defined

def register_page(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.creat_user(
                username=form.clean_data['username'],
                password=form.clean_data['password1'],
                email=form.clean_data['email']
                )
            return HttpResponseRedirect('/accounts/register/success/')
    else:
        form = RegistrationForm()
    variables = RequestContext(request, {'form': form})
    return render_to_response ('registration/register.html',variables)

When I run server, this error appears:

global name 'RegistrationForm' is not defined
Request Method: GET
Request URL:    http://127.0.0.1:8000/accounts/register/
Django Version: 1.4
Exception Type: NameError
Exception Value:    
global name 'RegistrationForm' is not defined
Exception Location: D:\Python\Scripts\littlesite\messageboard\views.py in register_page, line 31
Python Executable:  D:\Python\python.exe
Python Version: 2.7.2

Can anybody tell me what is wrong with it? Thanks.

Upvotes: 0

Views: 3546

Answers (1)

Danilo Bargen
Danilo Bargen

Reputation: 19482

You didn't import the RegistrationForm. In order to use it, you need to import it into your current namespace.

In case you're using django-registration, use the following import:

from registration.forms import RegistrationForm

If it's a custom form, import it from where you have defined it.

Upvotes: 1

Related Questions