Django之PopUp的具體實現(xiàn)方法
更新時間:2019年08月31日 16:40:30 作者:Quincy379
今天小編就為大家分享一篇Django之PopUp的具體實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
步驟一: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), ]
步驟三:視圖函數(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)閉當前窗口并執(zhí)行
function callbackns(text) { document.getElementById('hhh').innerText = text }
以上這篇Django之PopUp的具體實現(xiàn)方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關(guān)文章
基于python if 判斷選擇結(jié)構(gòu)的實例詳解
代碼執(zhí)行結(jié)構(gòu)為順序結(jié)構(gòu)、選擇結(jié)構(gòu)、循環(huán)結(jié)構(gòu)。這篇文章主要介紹了python if 判斷選擇結(jié)構(gòu)的相關(guān)知識,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2019-05-05關(guān)于python3安裝pip及requests庫的導(dǎo)入問題
小編最近快畢業(yè)了,閑著無事學(xué)習(xí)下python的內(nèi)容在學(xué)習(xí)到requsets庫的導(dǎo)入問題時遇到一些問題,通過查找相關(guān)資料問題順利解決,今天小編把問題解決思路及注意事項分享給大家供大家參考學(xué)習(xí)2021-05-05在 Python 應(yīng)用中使用 MongoDB的方法
這篇文章主要介紹了在 Python 應(yīng)用中使用 MongoDB的方法,需要的朋友可以參考下2017-01-01