Django之PopUp的具体实现方法
程序员文章站
2022-08-30 11:17:44
步骤一:index页面处理
<...
步骤一: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输出带颜色字体实例方法