[英]How to add query parameters to django-allauth LOGIN_REDIRECT_URL?
x
JS文件使用jsonp请求与服务器对话,该请求返回一个值,该值存储在变量x
x
stored inside the JS specific to the third party page 现在我想验证此用户,但要正确进行验证(为了使我的应用程序逻辑正常工作),我需要存储在特定于第三方页面的JS内的x
值 window.open("http://localhost:8000/accounts/facebook/login/?method=oauth2", "AskAFriend Facebook Login","menubar=0,toolbar=0;scrollbars=0;dialog=0;resizable=1,width=480px,height=320px");
the code above opens a new window for the facebook login process, which when completed redirects to a view i have designed in my django app, i have achieved this by providing the url to this view in the LOGIN_REDIRECT_URL
setting in settings.py
上面的代码为Facebook登录过程打开了一个新窗口,完成后重定向到我在django应用中设计的视图,我通过在settings.py
中的LOGIN_REDIRECT_URL
设置中提供该视图的网址来实现此目的
now i need a way to add a parameter to this request which can reach my view after the login completes, how can i achieve this? 现在, 我需要一种方法来向此请求添加参数,该参数可以在登录完成后到达我的视图,我该如何实现?
i have tried adding it to the url i used in my JS like window.open("http://localhost:8000/accounts/facebook/login/?method=oauth2&*valueofx=' + x* ...
(did not work)(ignore the *) 我已经尝试将其添加到我在JS中使用的URL中,例如window.open("http://localhost:8000/accounts/facebook/login/?method=oauth2&*valueofx=' + x* ...
(不是)工作)(忽略*)
I have read about overriding the get_login_redirect_url()
function by using a custom adapter but i can't figure out how to do it for my specific case 我已经阅读了有关使用自定义适配器覆盖get_login_redirect_url()
函数的信息,但我无法弄清楚如何针对我的特定情况
You could change LOGIN_REDIRECT_URL
to something like /redirect
and this will in turn be an 'intermediary' view that controls where the user gets redirected to. 您可以将LOGIN_REDIRECT_URL
更改为/redirect
而这又将是一个“中间”视图,用于控制用户重定向到的位置。
That view could look something like this (untested): 该视图可能看起来像这样(未经测试):
from django.views.generic import View
from django.http import HttpResponseRedirect
class LoginRedirectIntermediary(View):
"""
Decides where a newly logged in user should go based on the request.
"""
def get(self, request, *args, **kwargs):
if request.user.is_superuser:
url = '/admin-panel/{}/'
else:
url = '/user-panel/{}/'
return HttpResponseRedirect(url.format(request.user.username))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.