urls.py

urlpatterns = [
url('popup_test1',views.popup_test1),
url('popup_test2',views.popup_test2),
]

views.py

from django.shortcuts import render

def popup_test1(request):
return render(request,'popup_test1.html') def popup_test2(request):
if request.method == 'GET':
return render(request, 'popup_test2.html')
elif request.method == 'POST':
name= request.POST.get('city')
return render(request,'popup_test3.html',{'name':name})
popup_test1.html
callback 是回调函数,在数据处理完之后执行
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body> <h1>页面</h1>
<select name="" id="i1">
<option value="">上海</option>
<option value="">北京</option>
</select>
<input type="button" value="添加" onclick="PopFunc()"> <script>
function PopFunc() {
window.open('/popup_test2/','/popup_test2/',"status=1, height:500, width:600, toolbar=0, resizeable=0")
} function callback(name) {
var op = document.createElement('option');
op.innerHTML = name;
op.setAttribute('selected','selected');
document.getElementById('i1').appendChild(op)
}
</script>
</body>
</html>
popup_test2.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title> </head>
<body>
<form method="POST">
{% csrf_token %}
<input type="text" name="city" />
<input type="submit" value="提交" />
</form> </body>
</html>
popup_test3.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>正在返回</title> </head> <body> <script>
(function () {
var name = "{{ name }}";
window.opener.callback(name);
window.close();
})()
</script> </body>
</html>
 
 


Django popup示例的更多相关文章

  1. 用pycharm开发django项目示例

    pycharm开发django工程(一)  在pycharm(企业版)中新建Django工程,注意使用虚拟环境 创建成功后,在pycharm显示的工程目录结构如下: 打开pycharm的Termina ...

  2. python Django 文件下载示例

    from django.http import StreamingHttpResponse#文件流 def big_file_download(request): # do something... ...

  3. Django小示例

    创建项目,在命令行中输入:django-admin startproject mysite 则会创建一个名为mysite的项目.项目结构如下: +mysite |--+ugo |          | ...

  4. 新建Django项目示例--图书管理系统

    知识点: Django 1. 安装 1. Django版本 1.11.xx 2. 安装方式 1. 命令行 --> Python环境(双版本,pip的使用) 2. PyCharm安装 2. 创建D ...

  5. Django搭建示例项目实战与避坑细节

    Django 开发项目是很快的,有多快?看完本篇文章,你就知道了. 安装 Django 前提条件:已安装 Python. Django 使用 pip 命令直接就可以安装: pip install dj ...

  6. django搭建示例-ubantu环境

    python3安装--------------------------------------------------------------------------- 最新的django依赖pyth ...

  7. celery Django 简单示例

    一.目录结构 二.创建worker文件夹 __init__.py # -*- coding:utf-8 -*-import osfrom celery import Celery, platforms ...

  8. python的日志模块:logging;django的日志系统;django日志输出时间修改

    Django的log,主要是复用Python标准库中的logging模块,在settings.py中进行配置 源代码 1.__init__.py包含以下类: StreamHandler Formatt ...

  9. 【python】-- Django 分页 、cookie、Session、CSRF

    Django  分页 .cookie.Session.CSRF 一.分页 分页功能在每个网站都是必要的,下面主要介绍两种分页方式: 1.Django内置分页 from django.shortcuts ...

随机推荐

  1. 1.2Tensorflow的Session操作

    tf的session #-*- coding: utf-8 -*- # @Time : 2017/12/21 14:56 # @Author : Z # @Email : S # @File : 1. ...

  2. hihocoder 1284 - 机会渺茫

    N有N_cnt个约数,M有M_cnt个约数,那么总共有N_cnt * M_cnt种对应情况. 假设其中有D_cnt个对应结果是相等的,而这D_cnt个数正好是gcd(N,M)的所有约数. 例如: N= ...

  3. hadoop HA架构安装部署(QJM HA)

    ###################HDFS High Availability Using the Quorum Journal Manager########################## ...

  4. Oracle安装部署之linux OS install oracle database安装脚本

    #!/bin/bash#Purpose:Create and config oracle install.#Usage:Log on as the superuser('root') #1.creat ...

  5. Sorted sets

    Redis in Action JOSIAH L. CARLSON MANNING Shelter Island ZSETs offer the ability to store a mapping ...

  6. SQL语句常见视图操作部分试题(一)

    创建一个名称为EMPLOYEES_VU的视图,它基于EMPLOYEES表中的雇员号.雇员名和部门号.将雇员名的列标题改为EMPLOYEE. CREATE VIEW EMPLOYEES_VU AS SE ...

  7. 浅谈CSRF攻击方式(转)

    add by zhj: 在看Django开发的应用时,看到了CSRF,然后搜到了这篇文章,讲的不错.其实CSRF 攻击也蛮简单的.当你登陆网站A后,会在本地存有cookie,在cookie没有过期的情 ...

  8. grunt学习二

    1. 新建文件和文件目录 mkdir grunt-in-action cd grunt-in-action cd grunt-in-action mkdir grunt-empty cd grunt- ...

  9. ul li剧中对齐

    html: <div class="footernav"> <ul> <li>首页</li> <li>文章</li ...

  10. PHP生成zip压缩包

    /* * $res = new MakeZip($dir,$zipName); *@ $dir是被压缩的文件夹名称,可使用路径,例 'a'或者'a/test.txt'或者'test.txt' *@ $ ...