你好所有你有幫助的人在那裏(和再見沒有幫助的人:D)。我試圖在django(1.2.4)中創建一個用戶,然後在保存它們之後登錄它們。我的問題是我得到NotImplementedError並看着它被django.contrib.auth.models.AnonymousUser引發的追蹤。下面是我的看法代碼的一部分:Django問題與創建用戶然後登錄他們
def signup(request):
if request.method == 'POST': # If the form has been submitted...
p = request.POST
if not request.user.is_authenticated():
form = UserForm(request.POST) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
# Process the data in form.cleaned_data
# ...
form.save()
user=authenticate(username=p['username'],password=p['password'])
login(request,user)
return HttpResponseRedirect('/') # Redirect after POST
所以在我看來,它是試圖登錄的用戶anymouse,而不是一個我認證,我如何克服這個問題?
謝謝 P.S.用戶正在數據庫中創建,它只是不會使用此代碼登錄它們。
回溯:
環境:
請求方法:POST
請求URL:http://localhost:8000/signup/
Django的版本:1.2.4
Python版本:2.6.1
安裝的應用程序:
[ 'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'django.contrib.admindocs',
'django_extensions',
'REDACTED_APPs', 安裝中間件: ( 'django.middleware.common.CommonMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware' , 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.cont rib.messages.middleware.MessageMiddleware」, 'django.contrib.sessions.middleware.SessionMiddleware')
Traceback:
File "/Library/Python/2.6/site-packages/django/core/handlers/base.py" in get_response
100. response = callback(request, *callback_args, **callback_kwargs)
File "REDACTED/views.py" in signup
19. login(request,user)
File "/Library/Python/2.6/site-packages/django/contrib/auth/__init__.py" in login
71. user.save()
File "/Library/Python/2.6/site-packages/django/contrib/auth/models.py" in save
430. raise NotImplementedError
Exception Type: NotImplementedError at /signup/
Exception Value:
請發佈追蹤! – Wogan 2011-02-17 03:43:00