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

yipeiwu_com7年前Python基础

描述

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的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python pytest进阶之fixture详解

前言 学pytest就不得不说fixture,fixture是pytest的精髓所在,就像unittest中的setup和teardown一样,如果不学fixture那么使用pytes...

详解Python 解压缩文件

详解Python 解压缩文件

zipfile模块及相关方法介绍: 1 压缩 1.1 创建zipfile对象 zipfile.ZipFile(file, mode='r', compression=0, allowZi...

关于PyTorch 自动求导机制详解

关于PyTorch 自动求导机制详解

自动求导机制 从后向中排除子图 每个变量都有两个标志:requires_grad和volatile。它们都允许从梯度计算中精细地排除子图,并可以提高效率。 requires_grad 如...

python 将md5转为16字节的方法

python的hashlib库中提供的hexdigest返回长度32的字符串。 直接通过digest返回的16字节,有不可打印字符。 问题来了,因为md5sum是128bit,也就是16...

python定时器(Timer)用法简单实例

本文实例讲述了python定时器(Timer)用法。分享给大家供大家参考。具体如下: # encoding: UTF-8 import threading #Timer(定时器)是T...