【问题标题】:Error on account activation django_registration_email账户激活错误 django_registration_email
【发布时间】:2014-01-30 08:50:59
【问题描述】:

我已经使用 django_registration 和 django_registration 电子邮件在我的应用程序上实现了身份验证。这是我的代码:

settings.py

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',

#custom apps
'order',
'fiesta',

#3rd party apps
'south',
'jquery',
'djangoformsetjs',

# DEVELOPER TOOLS
'debug_toolbar',
#authentication apps
'registration',
'registration_email',

)

#DJANGO REGISTRATION SETTINGS

ACCOUNT_ACTIVATION_DAYS = 7 # one week activation window

AUTHENTICATION_BACKENDS = (
'registration_email.auth.EmailBackend',
)

LOGIN_REDIRECT_URL = '/'

urls.py

urlpatterns = patterns('',
url(r'^$', lambda x:HttpResponseRedirect("/fiesta/workspace/"), name="home"),
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/', include('registration_email.backends.default.urls')),
url(r'^fiesta/', include('fiesta.urls')),

)

注册邮件发送正常,但是当我点击帐户激活链接时,出现以下错误:

Traceback:
File "/home/blaqx/.virtualenv/django5/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
115.response = callback(request, *callback_args, **callback_kwargs)
File "/home/blaqx/.virtualenv/django5/lib/python2.7/site-packages/django/views/generic/base.py" in view
68.return self.dispatch(request, *args, **kwargs)
File "/home/blaqx/.virtualenv/django5/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
86.return handler(request, *args, **kwargs)
File "/home/blaqx/.virtualenv/django5/lib/python2.7/site-packages/registration/views.py" in get
126.success_url = self.get_success_url(request, activated_user)

Exception Type: TypeError at /accounts/activate/bf93e2619ad0b7419b34dc0284e172fae8ecafef/
Exception Value: 'str' object is not callable

在错误中,我可以看到在帐户激活期间,引用了 django-registration 而不是 django-registration-email。但是,我不知道这是否是错误的原因以及如何解决它。任何帮助将不胜感激。

【问题讨论】:

  • 当您说:帐户激活链接时,您的 urls.py 中的链接和该链接的视图指向哪里?
  • LearningNeverStops, url(r'^accounts/', include('registration_email.backends.default.urls')) 将注册网址映射到各自的视图。查看 django_registration_email 设置说明。

标签: python django django-registration


【解决方案1】:

首先,您将两个包用于相同目的(即发送电子邮件激活),这里是包,

  1. django-registration-email
  2. django 注册

从上面选择一个包。我选择 django-registration,这里是 doc https://django-registration.readthedocs.org

并按照代码说明进行操作,

settings.py

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',

#custom apps
'order',
'fiesta',

#3rd party apps
'south',
'jquery',
'djangoformsetjs',

# DEVELOPER TOOLS
'debug_toolbar',
#authentication apps
'registration',
#'registration_email',
)

#DJANGO REGISTRATION SETTINGS

ACCOUNT_ACTIVATION_DAYS = 7 # one week activation window

#AUTHENTICATION_BACKENDS = (
#'registration_email.auth.EmailBackend',
#)

LOGIN_REDIRECT_URL = '/'

urls.py

urlpatterns = patterns('',
url(r'^$', lambda x:HttpResponseRedirect("/fiesta/workspace/"), name="home"),
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/', include('registration.backends.default.urls')),
url(r'^fiesta/', include('fiesta.urls')),
)

【讨论】:

  • Dhana,在应用程序中,我打算使用 django-registration-email,以便使用电子邮件作为注册的唯一字段。请参阅github.com/bitmazk/django-registration-email。上面的设置我已经用过几次了,但我不知道这次错误是从哪里来的。
猜你喜欢
  • 2015-12-26
  • 2016-05-09
  • 1970-01-01
  • 2016-08-01
  • 2015-12-01
  • 2012-12-04
  • 2013-01-12
  • 2020-08-08
  • 1970-01-01
相关资源
最近更新 更多