Django 在iframe里跳转顶层url

描述

A网页为一个专门设计的登录页面login.html,通过iframe嵌套在B页面中index.html,登录后会进入后台C页面consule.html.问题来了,登录成功后,通过Django-url跳转,页面一直在iframe里面,没有跳出嵌入的框架中。

解决方法

通过HttpResponse来返回一段js脚本,直接让你丫的跳,代码如下

def login(request):
    login_form = loginForm()
    if request.method == 'POST':
        login_form = loginForm(request.POST)
        if login_form.is_valid():
            username = login_form.data['username']
            #通过js来跳转页面,取巧
            jump_to_console = '''<html><body onLoad="window.top.location.href='./index_console'" ></body></html>'''
            response = HttpResponse(jump_to_consule)
            response.set_cookie("username",username") 
            return response
        else:
            pass
    return render_to_response('login_iframe.html', {'form': login_form},)
posted @ 2017-03-24 11:50  猫影  阅读(276)  评论(0)    收藏  举报