2012-04-04 105 views
0
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) 

當我運行服務器,出現此錯誤:全局名稱「RegistrationForm」沒有定義

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 

誰能告訴我什麼是錯呢?謝謝。

+1

看起來相當明顯:您沒有定義RegistrationForm,或者您沒有導入它。你不明白什麼? – 2012-04-04 09:25:41

+0

在您的項目文件中搜索'RegistrationForm',然後導入... – mshsayem 2012-04-04 09:27:34

+0

即'from myapp.forms import RegistrationForm' – 2012-04-04 09:32:30

回答

1

您沒有導入RegistrationForm。爲了使用它,你需要將它導入你當前的命名空間。

如果你使用django-registration,請使用以下導入:

from registration.forms import RegistrationForm 

如果它是一個自定義表單,從已定義它導入。

相關問題