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

爱蒂网

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

2020-03-16 04:30:46 分类 / 代码专栏 来源 / 互联网

今天小编就为大家分享一篇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='https://www.aidi.net.cn//article/./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的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持爱蒂网。

猜你喜欢