【问题标题】:Django-registration: how to include a custom backend?Django-registration:如何包含自定义后端?
【发布时间】:2012-05-06 07:25:25
【问题描述】:

我创建了一个自定义后端以在 html 中包含激活电子邮件,而无需编辑 django 注册码

(参考django+ send email in html with django-registration,最后一个答案)

这是后端,存储在core/registration/backends/htmldefault/__init__.py中,就像存储在registration/backends/__init__.py中的DefaultBackend一样

from registration.forms import RegistrationForm
from core.models import HtmlRegistrationProfile

class HtmlDefaultBackend(object):
   #etc same as DefaultBackend but using HtmlRegistrationProfile instead of RegistrationProfile

这是我的 urls.py

urlpatterns = patterns('',
    #...
    url(r'^accounts/register/$', register, {'backend': 'core.registration.backends.htmldefault.HtmlDefaultBackend','form_class': UserRegistrationForm}, name='registration_register'),
    url(r'^accounts/', include('registration.urls')),
    #...
)

但我明白了

ImproperlyConfigured at /accounts/register/

Error loading registration backend core.registration.backends.htmldefault: "No module named registration.backends.htmldefault"

/registration/backends/__init__.py in get_backend, line 27抛出

我要问的是.. 是否可以在注册包之外有一个自定义的 django-registration 后端?或者它必须像简单和默认后端一样位于 /registration/backends/ 下?

【问题讨论】:

    标签: python django django-registration


    【解决方案1】:

    有可能。

    1. 检查您的所有文件夹(核心、注册、后端、 htmldefault)有__init__.py(可以为空)。

    2. 核心文件夹在项目目录中?

    【讨论】:

    • 2 个愚蠢的错误.. 首先是您的第 1 点,我没有在每个文件夹中创建 init.py(这是一个非常糟糕的失误),然后创建了该路径与注册包冲突..现在一切正常,谢谢
    猜你喜欢
    • 2013-05-05
    • 2011-06-23
    • 2017-05-08
    • 2016-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-13
    • 1970-01-01
    相关资源
    最近更新 更多