Facebook登录后如何重定向到弹出窗口 [英] How to get redirected to a popup after Facebook login

查看:249
本文介绍了Facebook登录后如何重定向到弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的django应用程序,我有一个Facebook连接按钮(通过django allauth)。当我点击它时,会出现对话框。现在,我希望登录后,用户被重定向到用户的朋友列表的弹出窗口(bootstrap模态)。



我有一个测试功能来获取我的views.py中的朋友列表,它的效果很好。我需要的是,在facbook对话框登录后,它将转到此功能,获取friendlist,并将结果返回到原始页面上的弹出窗口。



我尝试设置LOGIN_REDIRECT_URL ='/ friends',这需要我查看功能并获取好友列表,但是如何在该弹出窗口中显示此列表?我使用django-allauth与引导库。



对此的任何帮助将不胜感激。

解决方案

加载模式中的朋友页面



您可以使用远程选项的模态,从模式中的朋友页面加载html。请参阅文档,并查找 remote



向要显示模态的页面添加一个模态:

 < div class =modal hide fadeid =myModalFriendsaria-hidden =truedata-show =true> 
< div class =modal-header>
< h3>朋友列表< / h3>
< / div>
< div class =modal-body> Friend页面将在此处加载。< / div>
< div class =modal-footer>
< button class =btndata-dismiss =modalaria-hidden =true>关闭< / button>
< / div>
< / div>

然后,成功登录后:

  $('#myModalFriends')。modal({
remote:'/ friends'
});

这将从您的 / friends 页面里面一个模态。



打开一个模式框的朋友页面加载



如果要在朋友页面的模式框中显示您的朋友列表,可以在文档中调用 $('#myModal').modal(); 在启动时显示;请参阅这个小提琴


on my django app, I have a Facebook connect button (via django allauth). When I click that, the facebook dialog box appears. Now, i want that after login, the user is redirected to a popup (bootstrap modal) with the list of friends of the user.

I have a test function for obtaining the list of friends in my views.py and it works well. What I need is that after the facbook dialog box login, it goes to this function, gets the friendlist, and return the result in a popup on the original page.

I tried setting LOGIN_REDIRECT_URL = '/friends', which takes me to the view function and gets the friendlist, but how do I show this list in that popup? I'm using django-allauth with the bootstrap library.

Any help on this would be greatly appreciated.

解决方案

load the friends page inside a modal

You can use the remote option of the modal to load the html from the friends page inside the modal. See the docs and look for remote.

Add a modal to the page where you want to show the modal:

<div class="modal hide fade" id="myModalFriends" aria-hidden="true" data-show="true">
    <div class="modal-header">
         <h3>Friend list</h3>
    </div>
    <div class="modal-body">Friend page will load here.</div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    </div>
</div>

Then, after successful login:

$('#myModalFriends').modal({
    remote: '/friends'
});

This will load the html from your /friends page inside a modal.

open a modal box the friend page loads

If you want to show your friend list in a modal box on the friends page, you can call $('#myModal').modal(); in document ready to show it on startup; see this fiddle.

这篇关于Facebook登录后如何重定向到弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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