Django之PopUp的具体实现方法

yipeiwu_com5年前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设计】。

相关文章

python3.7 sys模块的具体使用

Python的sys模块提供访问解释器使用或维护的变量,和与解释器进行交互的函数。通俗来讲,sys模块负责程序与python解释器的交互,提供了一系列的函数和变量,用于操控python运...

python实现画圆功能

python实现画圆功能

本文实例为大家分享了python实现画圆功能的具体代码,供大家参考,具体内容如下 # -*- coding: utf-8 -*- """ __author__= 'Du' __...

Python类的继承、多态及获取对象信息操作详解

本文实例讲述了Python类的继承、多态及获取对象信息操作。分享给大家供大家参考,具体如下: 继承 类的继承机制使得子类可以继承父类中定义的方法,拥有父类的财产,比如有一个Animal的...

Python 实现的 Google 批量翻译功能

首先声明,没有什么不良动机,因为经常会用 translate.google.cn,就想着用 Python 模拟网页提交实现文档的批量翻译。据说有 API,可是要收费。 生成 Token...

使用OpenCV-python3实现滑动条更新图像的Canny边缘检测功能

使用OpenCV-python3实现滑动条更新图像的Canny边缘检测功能

import cv2 from matplotlib import pyplot as plt import numpy as np img= cv2.imread('39.jpg...