你好所有你有帮助的人在那里(和再见没有帮助的人: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