看淡拥有,不刻意追求某些东西,落叶归根,那些属于你的,总会回来。劳动的意义不仅在于追求业绩,更在于完善人的心灵。
描述
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.rel="nofollow noopener noreferrer" 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},)
以上这篇Django 在iframe里跳转顶层url的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。