所以,我正在尝试编写自己的注册后端,因为我必须和我遇到一些麻烦。
我明白了:
HttpResponse对象没有属性get_absolute_url
并且不知道如何解决这个问题。
这是我的代码:
class MyRegistrationBackend(object):
def register(self, request, **kwargs):
username, email, password = kwargs['username'], kwargs['email'], kwargs['password1']
encode_drupal = DrupalPasswordHasher()
password = encode_drupal.create(str(password),"E","LOhihi6WNUA.") #drupal style hasher
print "sha512 pass: ", password
#ask if user is already registered
req = urllib2.Request(settings.DJANGO_SERVER+"/api/stats/customuser/"+username+"/?format=json",
headers = {"Authorization": basic_authorization(settings.DJANGO_OAUTH_USERNAME, settings.DJANGO_OAUTH_PASSWORD),"Content-Type": "application/json"}
)
resp = json.loads(urllib2.urlopen(req).read())
print resp
if resp['username']!='':
#do something
else:
if resp['password'] != password: #password does not match received pass
print "wrong credentials"
return render_to_response('registration/error.html')
追溯:
Environment:
Request Method: POST
Request URL: http://192.168.1.77:8000/accounts/register/
Django Version: 1.4.2
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'registration',
'administration',
'tastypie',
'south',
'social_auth',
'django_extensions',
'djcelery',
'braces',
'django.contrib.admin',
'django.contrib.admindocs')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.gzip.GZipMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'youbeqadmin.middleware.crossdomainxhr.XsSharing')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/registration/views.py" in register
189. to, args, kwargs = backend.post_registration_redirect(request, new_user)
File "/home/psychok7/git/mysite/mysite/backends.py" in post_registration_redirect
126. return (user.get_absolute_url(), (), {})
Exception Type: AttributeError at /accounts/register/
Exception Value: 'HttpResponse' object has no attribute 'get_absolute_url'
有什么想法吗?我认为这与某些事情有关:
选择render_to_response
,但我不知道如何解决这个问题。
更新:
如果我返回None,我得到:
'NoneType'对象没有属性'get_absolute_url'
答案 0 :(得分:1)
Django后端需要返回一个User对象(或具有get_absolute_url
的等效对象),或者需要返回None
(here's an example)。您的身份验证库不应该重定向,这是您的view
'工作。