Django之PopUp的具体实现方法

作者:Quincy379 时间:2023-03-26 13:04:54 

步骤一: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
}

来源:https://blog.csdn.net/qq_33733970/article/details/78874832

标签:Django,PopUp
0
投稿

猜你喜欢

  • 基于Node.js实现nodemailer邮件发送

    2024-05-03 15:36:40
  • MySQL中datetime和timestamp的区别及使用详解

    2024-01-19 05:58:28
  • python使用turtle库绘制树

    2022-04-14 09:09:06
  • mysql清空表数据的两种方式和区别解析

    2024-01-18 09:40:40
  • 实例讲解如何利用crontab定时备份MySQL

    2009-01-04 13:06:00
  • 浅谈Pycharm最有必要改的几个默认设置项

    2021-10-13 05:33:38
  • 在pytorch中查看可训练参数的例子

    2021-09-18 09:44:06
  • 基于js实现抽红包并分配代码实例

    2024-04-16 09:30:58
  • python中翻译功能translate模块实现方法

    2021-05-09 17:02:33
  • 教你使用python做一个“罚点球”小游戏

    2022-10-12 00:09:03
  • Python调用C语言的实现

    2021-10-15 11:48:53
  • Python 字典与字符串的互转实例

    2023-06-27 07:51:22
  • keras之权重初始化方式

    2023-06-01 19:04:44
  • pandas实战:分析三国志人物示例实现

    2023-07-12 21:11:46
  • Python-split()函数实例用法讲解

    2023-12-12 07:13:20
  • Windows和Linux下Python输出彩色文字的方法教程

    2021-04-15 11:15:41
  • 详解基于Transformer实现电影评论星级分类任务

    2022-01-08 20:31:23
  • mybatis plus实体类中字段映射mysql中的json格式方式

    2024-01-22 16:11:37
  • python语法学习print中f-string用法示例

    2021-01-08 11:11:24
  • python获得图片base64编码示例

    2023-10-29 07:02:37
  • asp之家 网络编程 m.aspxhome.com