您好,登錄后才能下訂單哦!
步驟一: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/')">點(diǎn)我點(diǎn)我</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), ]
步驟三:視圖函數(shù)
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})
步驟四:構(gòu)建一個前端頁面
<!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>
步驟五:自執(zhí)行函數(shù)處理
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>正在關(guān)閉...</title> </head> <body> <script> (function () { opener.callbackns("{{ text }}"); window.close() })() </script> </body> </html>
步驟六:關(guān)閉當(dāng)前窗口并執(zhí)行
function callbackns(text) { document.getElementById('hhh').innerText = text }
以上這篇Django之PopUp的具體實(shí)現(xiàn)方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。