我已经django-registration-redux
工作但是在尝试使用自定义表单并设置自定义success_url时,它没有这样做。如果我更改BaseRegistrationView
的源代码然后它会工作,为什么会发生这种情况?我相信我压倒一切。
registration
位于我的INSTALLED_APPS顶部。我已经迁移了。
forms.py
from django import forms
from registration.forms import RegistrationFormUniqueEmail
class UserProfileRegistrationForm(RegistrationFormUniqueEmail):
field = forms.CharField()
URLs.py
import logging
logging.basicConfig(filename='example.log', level=logging.DEBUG)
from django.conf import settings
from django.conf.urls import url, include
from django.conf.urls.static import static
from django.contrib import admin
from registration.backends.simple.views import RegistrationView
from myapp.models import UserProfile
from myapp.forms import UserProfileRegistrationForm
class MyRegistrationView(RegistrationView):
logging.debug("Class initialised")
success_url = '/test/'
form_class = UserProfileRegistrationForm
def register(self, form_class):
logging.debug("Registering")
new_user = super(MyRegistrationView, self).register(form_class)
user_profile = UserProfile()
user_profile.user = new_user
user_profile.field = form_class.cleaned_data['field']
user_profile.save()
logging.debug(user_profile)
return user_profile
def get_form_class(self):
logging.debug("Getting form class")
return UserProfileRegistrationForm
urlpatterns = [
url(r'^', include('myapp.urls')),
url(r'^accounts/', include('registration.backends.simple.urls')),
url(r'^accounts/register/$', MyRegistrationView.as_view(form_class=UserProfileRegistrationForm), name="registration_register"),
url(r'^accounts/password/change/$', MyRegistrationView.as_view(), name="auth_password_change"),
url(r'^accounts/password/change/done/$', MyRegistrationView.as_view(), name="auth_password_changed"),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
记录"注册"永远不会受到打击,而且#34;获取表格课程"。
我已为RegistrationView
尝试了所有5种可能的导入:
registration.views.RegistrationView
registration.backends.hmac.views.RegistrationView
registration.backends.simple.views.RegistrationView
registration.backends.default.views.RegistrationView
registration.backends.model_activation.views.RegistrationView
答案 0 :(得分:0)
在包含默认网址之前,您需要包含自定义视图。否则Django将首先匹配默认网址,并且永远不会使用您的自定义视图。
url(r'^accounts/register/$', MyRegistrationView.as_view(form_class=UserProfileRegistrationForm), name="registration_register"),
...
url(r'^accounts/', include('registration.backends.simple.urls')),