覆盖注册视图django-allauth

San*_*ire 8 python django django-allauth

我要求用户用自定义表单填写额外的字段.在其中一个领域,我必须让用户选择多个分层标签.为此,我需要将标记从视图传递到模板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
Run Code Online (Sandbox Code Playgroud)

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

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

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

Lau*_*van 8

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

否则,@ PauloAlmeida是正确的.您可以使用以下内容继承新类SignupView:

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
Run Code Online (Sandbox Code Playgroud)

我宁愿使用自定义表单方法,因为它不会搞砸了urls.py.