覆盖注册视图django-allauth [英] Override signup view django-allauth

查看:70
本文介绍了覆盖注册视图django-allauth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要用户用自定义表格填写额外的字段。在其中一个字段中,我必须让用户选择多个层次结构标签。为此,我需要将视图中的标签传递到模板signup.html

I am asking user to fill extra fields with custom form. And in one of the fields, I have to let user choose multiple hierarchical tags. For this, I need to pass the tags from a view to the template signup.html

from classes.Tags import Tags
from django.shortcuts import render_to_response
from allauth.socialaccount import views as signup_views

def signup_view(request):
    tags = Tags()
    parameters={}
    all_tags = tags.get_tags()
    parameters['all_tags'] = all_tags
    response = signup_views.signup(request)
    return response

在urls.py中,我在allauth url包含行之前添加了这一行。

And in urls.py, I added this line before the allauth urls include line.

url(r'^accounts/social/signup/', 'mainapp.signup_views.signup_view', name = 'account_signup'),
url(r'^accounts/', include('allauth.urls')),

我需要的是将all_tags添加到响应中,以便我可以从模板访问它。我该怎么做?

What I need is that I need to add all_tags to the response so that I can access it from the template. How do I do that?

推荐答案

此链接包含有关使用您自己的注册表单的一些详细信息。 IMO,您可以定义自己的形式(最终使用标签的自定义小部件)并直接使用它,而不必弄乱视图。

This link has some details on using your own signup form. IMO, you can define your own form (eventually with a custom widget for the tags) and use it directly, without having to mess with the view.

否则,@ PauloAlmeida是正确的。您可以从 SignupView 继承一个新类,如下所示:

Otherwise, @PauloAlmeida is correct. You could inherit a new class off SignupView with something like:

class MySignupView(SignupView):

    def get_context_data(self, **kwargs):
        ret = super(MySignupView, self).get_context_data(**kwargs)
        ret['all_tags'] = Tags.get_tags()

        return ret

我想宁愿使用自定义表单方法,因为它不会弄乱 urls.py

I'd rather use the custom form approach as it won't mess up the urls.py.

这篇关于覆盖注册视图django-allauth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆