gpt4 book ai didi

python - django-registration 将 extra_context 传递给注册表

转载 作者:行者123 更新时间:2023-11-28 22:52:56 25 4
gpt4 key购买 nike

我刚刚改用 django-registration 来管理我网站上的用户身份验证。之前,我为注册和登录页面使用了 View ,因此能够指定上下文参数。但是现在,我不再有这些页面的 View ,因为 django-registration 为我处理了这件事。不过我仍然需要传递上下文变量,所以我试过这个:

网址.py:

import registration
from registration.backends.default.views import RegistrationView
...
(r'^accounts/login/$', 'django.contrib.auth.views.login', { 'extra_context' : {'design_form': True }}),
(r'^accounts/register/$', RegistrationView.as_view(form_class=RegistrationForm), { 'extra_context' : {'design_form': True }}),
(r'^accounts/', include('registration.backends.default.urls')),

“design_form”参数在帐户/登录/页面上正常运行,但未传递到注册页面。如何将 extra_context 传递到我的注册页面?

使用 django 1.5 和 django-registration 1.0

最佳答案

因为 RegistrationForm 是 django.views.generic.FormView 的后代,又是 django.generic.views.View,传递 extra_contentoverriding get_context_data 完成,示例包括在内。

Function-based generic views provided an extra_context argument as way to insert extra items into the context at time of rendering.

Class-based views don’t provide an extra_context argument. Instead, you subclass the view, overriding get_context_data().

关于python - django-registration 将 extra_context 传递给注册表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19864048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com