匿名用户错误编辑

时间:2012-11-29 12:10:12

标签: python django facebook authentication django-facebook

我已经为我的网站安装了 django-facebook-4.0.8 。该软件包已成功安装,但提供了不同类型的错误。 请帮忙!

我正在使用AUTH_PROFILE_MODULE ='django_facebook.FacebookProfile'。

它将用户注册为 AUTH用户,但未在django_facebook_facebookprofile表中注册。 注册后,'AnonymousUser'对象没有属性'后端'

这是我的追溯:

Environment:

Request Method: POST
Request URL: http://pydev.aviesta.com/facebook/connect/?facebook_login=1

Django Version: 1.4.2
Python Version: 2.6.6
Installed Applications:
['mezzanine.boot',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.redirects',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.sitemaps',
'django.contrib.staticfiles',
'cartridge.shop',
'mezzanine.conf',
'mezzanine.core',
'mezzanine.generic',
'mezzanine.blog',
'mezzanine.forms',
'mezzanine.pages',
'mezzanine.galleries',
'mezzanine.twitter',
'mezzanine.accounts',
'user_attr',
'facebook',
'django_facebook',
'django_extensions',
'filebrowser_safe',
'south',
'grappelli_safe',
'django.contrib.admin',
'django.contrib.comments']
Installed Middleware:
['django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'cartridge.shop.middleware.ShopMiddleware',
'mezzanine.core.request.CurrentRequestMiddleware',
'mezzanine.core.middleware.TemplateForDeviceMiddleware',
'mezzanine.core.middleware.TemplateForHostMiddleware',
'mezzanine.core.middleware.AdminLoginInterfaceSelectorMiddleware',
'mezzanine.pages.middleware.PageMiddleware']

Traceback:
File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response

response = middleware_method(request, callback, callback_args, callback_kwargs) File "/usr/lib/python2.6/site-packages/mezzanine/pages/middleware.py" in process_view
return view_func(request, *view_args, **view_kwargs) File "/usr/lib/python2.6/site-packages/django/views/decorators/csrf.py" in wrapped_view
return view_func(*args, **kwargs) File "/usr/lib/python2.6/site-packages/django_facebook/decorators.py" in _wrapped_view
return view_func(request, *args, **kwargs) File "/usr/lib/python2.6/site-packages/django_facebook/views.py" in connect
response = _connect(request, facebook_login) File "/usr/lib/python2.6/site-packages/django_facebook/views.py" in _connect
action, user = connect_user(request) File "/usr/lib/python2.6/site-packages/django_facebook/connect.py" in connect_user
user = _login_user(request, facebook, auth_user, update=False) File "/usr/lib/python2.6/site-packages/django_facebook/connect.py" in _login_user
login(request, authenticated_user) File "/usr/lib/python2.6/site-packages/django/contrib/auth/__init__.py" in login
request.session[BACKEND_SESSION_KEY] = user.backend File "/usr/lib/python2.6/site-packages/django/utils/functional.py" in inner
return func(self._wrapped, *args)
Exception Type: AttributeError at /facebook/connect/
Exception Value: 'AnonymousUser' object has no attribute 'backend'

1 个答案:

答案 0 :(得分:1)

基本上你在打电话

self.login(request, user)

不打电话

authenticate(username=user, password=pwd)

第一

当您调用authenticate时,django会在用户上设置后端属性,并注明要使用哪个后端,有关详细信息,请参阅此处https://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.authenticate