python

超轻量级php框架startmvc

Django之PopUp的具体实现方法

更新时间:2020-07-28 23:18:02 作者:startmvc
步骤一:index页面处理<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title&g

步骤一: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的具体实现方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

Django PopUp