django-registration视图定制
我正在使用 django-registration (请参阅:https://bitbucket.org/ ubernostrum/django-registration )在我的一个项目中。 django-registration 的标准设置是在 urls.py
文件中添加以下代码
(r'^accounts/', include('registration.urls'))
,并在名为 registration
的文件夹中自定义模板。
上面的代码创建了注册、登录和密码恢复的链接,这很好。但在我的项目中,我通常会添加一些其他功能到我的视图中,因此如果我只添加 include('registration.urls')
,我似乎无法自定义包含这些 django 的视图- 登记表。
有没有办法在视图中调用 django-registration 使用的表单,以便我可以在这些视图上添加更多内容?
I'm using django-registration
(see: https://bitbucket.org/ubernostrum/django-registration ) on one of my projects. The standard setup for the django-registration is to add a the code below in the urls.py
file
(r'^accounts/', include('registration.urls'))
and also customize the templates in a folder called registration
.
The code above is creating links to the registration, login and password recovery which is fine. But in my project there are some other functions I usually add to my views so if I just add the include('registration.urls')
it appears that I have no way of customizing the views containing those django-registration forms.
Is there a way to call the forms used by the django-registration
in a view so I can add a few more things on those views ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
注册表由注册后台提供。查看registration.backends.default.DefaultBackend。
有一个方法
get_form_class(request)
返回registration.forms.RegistrationForm
类。您所要做的就是创建一个新的后端,继承自DefaultBackend
并重写get_form_class()
方法以返回新的表单类。除了更改注册应用程序的基本行为之外,您几乎可以通过提供自定义后端来执行任何操作。如果您需要以提供自定义后端无法满足要求的方式从根本上自定义视图,那么只需创建一个
authn
或users
应用程序并从其中导入任何位您发现 django-registration 很有用。例如,您可以将默认模型和管理器保留在registration
应用命名空间内,但将自定义后端连接到新应用中您自己的内部结构。The registration form is provided by the registration backend. Check out
registration.backends.default.DefaultBackend
.There's a method
get_form_class(request)
that returns theregistration.forms.RegistrationForm
class. All you have to do is create a new backend, inherit fromDefaultBackend
and override theget_form_class()
method to return a new form class.You can pretty much do anything by providing a custom backend, except changing the base behavior of the registration app. If you need to radically customize the views in a manner that providing a custm backend doesn't make the cut, then just create a
authn
orusers
app and import any bits from django-registration you find useful. You can, say, keep the default models and managers within theregistration
app namespace, but hook up a custom backend to your own internals in a new app.