这里是注册redux的views.py。我有点困惑,我真的不明白如何传递上下文变量。
class RegistrationView(BaseRegistrationView):
SEND_ACTIVATION_EMAIL = getattr(settings, 'SEND_ACTIVATION_EMAIL', True)
success_url = 'registration_complete'
def register(self, request, form):
if Site._meta.installed:
site = Site.objects.get_current()
else:
site = RequestSite(request)
if hasattr(form, 'save'):
new_user_instance = form.save()
else:
new_user_instance = UserModel().objects.create_user(**form.cleaned_data)
new_user = RegistrationProfile.objects.create_inactive_user(
new_user=new_user_instance,
site=site,
send_email=self.SEND_ACTIVATION_EMAIL,
request=request,
)
signals.user_registered.send(sender=self.__class__,
user=new_user,
request=request)
return new_user
答案 0 :(得分:0)
BaseRegistrationView继承自FormView,后者在其继承链django.views.generic.base.ContextMixin
中具有。这定义了get_context_data
方法,它将上下文作为dict返回。您可以覆盖该方法并添加自己的变量,如下所示:
class RegistrationView(BaseRegistrationView):
...
def get_context_data(self, **kwargs):
context = super(RegistrationView, self).get_context_data(**kwargs)
context['key'] = value
return context