[英]On Success URL redirect not working for custom view in django-allauth
I've created my own class LocalSignup which extends the base django-allauth SignupView class with my own form and my own validation logic. 我创建了自己的类LocalSignup,它使用自己的形式和验证逻辑扩展了django-allauth SignupView基类。 The problem is that on success I cannot get the view to redirect to anything but the django LOGIN_REDIRECT_URL
in my settings.py. 问题是,成功后,我无法将视图重定向到我的settings.py中的django LOGIN_REDIRECT_URL
任何内容。 I have included a success_url
field in my class based view; 我在基于类的视图中包含了success_url
字段; I have tried overriding the get_success_url
function (see below); 我试过重写get_success_url
函数(见下文); I have also tried passing my on success redirect using LocalSignup.as_view(success_url="/add_account_select/")
. 我还尝试使用LocalSignup.as_view(success_url="/add_account_select/")
传递成功重定向。 None have worked. 没有一个工作。 Any ideas on what I'm doing wrong? 关于我在做什么错的任何想法吗?
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
In the default view if there is "next" field in the sign-in form the view, allauth will automatically redirect to it. 在默认视图中,如果登录视图中存在“下一个”字段,则allauth将自动重定向到该视图。
<input id="login_redirect" type="hidden" name="next" value="#" />
complete form 完整表格
<form method="POST" action="{% url "account_login" %}">
{% csrf_token %}
{{form}}
<input type="hidden" name="next" value="/add_account_select/" />
<button type="submit" class="btn btn-primary">Sign IN</button>
</form>
Just to provide an up-to-date answer: 只是提供最新答案:
Using django-allauth=0.30.0, the following works nicely in views.py
使用django-allauth = 0.30.0,以下代码在views.py
可以很好地工作
from allauth.account.views import SignupView
class LocaLSignupView(SignupView):
success_url = '/page/to/redirect/to'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.