首页 > 编程 > Python > 正文

Django 在iframe里跳转顶层url的例子

2019-11-25 11:54:45
字体:
来源:转载
供稿:网友

描述

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},)

以上这篇Django 在iframe里跳转顶层url的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持武林网。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表