Django-registration:如何包含自定义后端?

时间:2021-07-08 18:16:40

I created a custom backend to have activation emails in html without editing django-registration code

我创建了一个自定义后端,在html中有激活电子邮件,而不需要编辑django注册代码

(ref. django+ send email in html with django-registration, last answer)

(ref. django+用django注册的html发送电子邮件,最后一个答案)

this is the backend, stored in core/registration/backends/htmldefault/__init__.py, like DefaultBackend that is stored in registration/backends/__init__.py

这是后端,存储在core/registration/backends/htmldefault/__init__中。py,类似于在注册/后端/__init__.py中存储的default后台

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

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

and this is my 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')),
    #...
)

But i get

但我得到

ImproperlyConfigured at /accounts/register/

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

thrown by /registration/backends/__init__.py in get_backend, line 27

/注册/后端/抛出的__init__。在get_后台,第27行

What i'm asking is.. is it possible to have a custom django-registration backend outside the registration package? Or it must live under /registration/backends/ like simple and default backends?

我问的是. .有可能在注册包之外有一个自定义的django注册后端吗?或者它必须生活在/注册/后端/像简单和默认后端?

1 个解决方案

#1


2  

It is possible.

这是可能的。

  1. Check if all your folders (core, registration, backends, htmldefault) have __init__.py (can be empty).

    检查所有文件夹(core, registration, backends, htmldefault)是否都有__init__。py(可以是空的)。

  2. Core folder is in project directory?

    Core文件夹在项目目录中吗?

#1


2  

It is possible.

这是可能的。

  1. Check if all your folders (core, registration, backends, htmldefault) have __init__.py (can be empty).

    检查所有文件夹(core, registration, backends, htmldefault)是否都有__init__。py(可以是空的)。

  2. Core folder is in project directory?

    Core文件夹在项目目录中吗?