Django之PopUp的具体实现方法

yipeiwu_com6年前Python基础

步骤一:index页面处理

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>首页</title>
</head>
<body>
<div id="hhh">hello</div>
<a href="" onclick=" rel="external nofollow" punch('/pop/')">点我点我</a>
</body>
<script>
  function punch(url) {
    window.open(url,url,"status=1,width:500,height:600,toolbar=0,resizeable=0")
  }
  function callbackns(text) {
    document.getElementById('hhh').innerText = text
  }
</script>
</html>

步骤二:配置路由

urlpatterns = [
  path('admin/', admin.site.urls),
  path('index/', views.index),
  path('pop/', views.pop),
]

步骤三:视图函数

from django.shortcuts import render


# Create your views here.
def index(request):
  """
  :param request:
  :return:
  """
  return render(request, 'test1.html')


def pop(request):
  """
  :param request:
  :return:
  """
  if request.method == 'GET':
    return render(request, 'test2.html')
  else:
    text = request.POST.get('content')

    return render(request, 'test3.html', {'text': text})

步骤四:构建一个前端页面

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>pop页面</title>
</head>
<body>
<form action="" method="post">
  {% csrf_token %}
  <input type="text" name="content">
  <input type="submit" value="提交">
</form>
</body>
</html>

步骤五:自执行函数处理

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>正在关闭...</title>
</head>
<body>
<script>

  (function () {
    opener.callbackns("{{ text }}");
    window.close()
  })()

</script>
</body>
</html>

步骤六:关闭当前窗口并执行

function callbackns(text) {
  document.getElementById('hhh').innerText = text
 }

以上这篇Django之PopUp的具体实现方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

详解Anconda环境下载python包的教程(图形界面+命令行+pycharm安装)

详解Anconda环境下载python包的教程(图形界面+命令行+pycharm安装)

一:图形界面安装 1、打开Anconda 2、点击Environment 3、 将Installed点击为Not installed 4、 搜索django,勾选django之后点击绿...

Python读写/追加excel文件Demo分享

三个工具包 python操作excel的三个工具包如下,注意,只能操作.xls,不能操作.xlsx。 • xlrd: 对excel进行读相关操作 • xlwt:...

django基于restframework的CBV封装详解

一.models数据库映射 from django.db import models # Create your models here. class Book(models.Mo...

Python简单实现查找一个字符串中最长不重复子串的方法

本文实例讲述了Python简单实现查找一个字符串中最长不重复子串的方法。分享给大家供大家参考,具体如下: 刚结束的一个笔试题,很简单,不多说简单贴一下具体的实现: #!usr/bin...

Python的ORM框架SQLObject入门实例

SQLObject和SQLAlchemy都是Python语言下的ORM(对象关系映射)解决方案,其中SQLAlchemy被认为是Python下事实上的ORM标准。当然,两者都很优秀。 一...