覆盖Django allauth注册“ next”;重定向网址 [英] Override Django allauth signup "next" redirect URL

查看:73
本文介绍了覆盖Django allauth注册“ next”;重定向网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设用户位于具有django-allauth的网站上的页面 / some_url / 中。单击登录时,它们将发送到以下网址:

Suppose a user is on the page /some_url/ on a site with django-allauth. When clicking "Login" they get sent to a URL like:

/accounts/login/?next=/some_url/

如果他们已经是注册用户,则在这里登录后,他们将被发送到 / some_url / ,这很好。

If they are already a registered user, after logging in here, they get sent to the /some_url/, which is fine.

但是如果他们没有注册,然后单击注册,就会被发送到:

But if they're not registered, and they click "sign up", they get sent to:

/accounts/signup/?next=/some_url/

假设我想在用户签约后立即在 / onboarding / 上为用户提供一些入职体验

Suppose I want to send the user to some onboarding experience, at /onboarding/, straight after they sign up.

最简单的方法是覆盖allauth的默认行为,并将用户发送到 / onboarding / 是否指定了 next = / some_url /

What's the simplest way to override allauth's default behaviour, and send the user to /onboarding/ even if a next=/some_url/ is specified?

推荐答案

最简单的方法将使用您自己的副本覆盖模板 account / signup.html 。如果您检查该模板,则会看到以下部分:

The simplest way would be to override the template account/signup.html with your own copy. If you examine that template you will see the following section:

{% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
{% endif %}

如果删除 if / endif 部分并更改其中的值,即使您传递 next,注册页面也会重定向到特定页面URL中的参数:

If you remove the if/endif part and change the value inside, the signup page will redirect to a specific page, even if you pass a next argument in the URL:

<input type="hidden" name="{{ redirect_field_name }}" value="/onboarding/" />

这篇关于覆盖Django allauth注册“ next”;重定向网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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