我创建了自己的类 LocalSignup,它使用我自己的表单和我自己的验证逻辑扩展了基础 django-allauth SignupView 类。问题是,成功后,我无法将视图重定向到LOGIN_REDIRECT_URL
settings.py 中的 django 以外的任何内容。我success_url
在基于班级的视图中包含了一个字段;我尝试过覆盖该get_success_url
功能(见下文);我也尝试过使用 LocalSignup.as_view(success_url="/add_account_select/")
. 没有一个工作。关于我做错了什么的任何想法?
class LocalSignup(SignupView):
form_class = AllAuthUserForm
template_name = 'signup/social_login.html'
success_url = '/add_account_select/' #reverse_lazy('add_account_select')
def get_success_url(self):
return '/add_account_select/' #reverse('add_account_select')
def dispatch(self, request, *args, **kwargs):
# self.sociallogin = request.session.get('socialaccount_sociallogin')
return super(LocalSignup, self).dispatch(request, *args, **kwargs)
def form_valid(self, form):
ret = super(LocalSignup, self).form_valid(form)
### MY FORM VALIDATION LOGIC
return ret
def get_context_data(self, **kwargs):
ret = super(LocalSignup, self).get_context_data(**kwargs)
ret.update(dict(username=self.sociallogin.account.user.first_name,
photo_url=self.sociallogin.account.get_avatar_url() ))
return ret