Django学习6:利用POST方式提交表单
来源:互联网 发布:php java .net的区别 编辑:程序博客网 时间:2024/06/07 06:02
1.在HelloWorld的app下新建search2.py, 代码如下:
# -*- coding:utf-8 -*-from django.shortcuts import renderfrom django.views.decorators import csrfdef search_post(request): ctx = {} if request.POST: ctx['rlt'] = request.POST['q'] return render(request, "post.html", ctx)
2.在templates下新建post.html文件,代码如下:
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Test Post</title></head><body> <form action="/search-post" method="post"> {% csrf_token %} <input type="text" name="q"> <input type="submit" value="submit"> </form> <p>{{ rlt }}</p></body></html>
3.修改urls.py文件:
from django.conf.urls import urlfrom . import search2from . import searchurlpatterns = { url(r'^search-post$', search2.search_post), # 可以 # url(r'^search', search.search),
4.在浏览器端输入 http://127.0.0.1:8000/search-post 即可看到效果:
阅读全文
0 0
- Django学习6:利用POST方式提交表单
- Django学习5:利用GET方式提交表单
- javascript POST方式提交表单
- JavaScript Post方式提交表单
- django 表单提交的几种方式
- C# Winform利用POST传值方式模拟表单提交数据(Winform与网页交互)
- C# Winform利用POST传值方式模拟表单提交数据(Winform与网页交互)
- C# Winform利用POST传值方式模拟表单提交数据(Winform与网页交互)
- C# Winform利用POST传值方式模拟表单提交数据(Winform与网页交互)
- C# Winform利用POST传值方式模拟表单提交数据
- C# Winform利用POST传值方式模拟表单提交数据(Winform与网页交互)
- Winform利用POST传值方式模拟表单提交数据(Winform与web交互)
- C# Winform利用POST传值方式模拟表单提交数据(Winform与网页交互)
- C# Winform利用POST传值方式模拟表单提交数据(Winform与网页交互)
- 深入研究表单提交方式:GET/POST
- 表单的提交方式POST和GET
- c#以POST方式模拟提交表单
- 深入研究表单提交方式:GET/POST
- [HDU 6047]Maximum Sequence
- C语言,全局变量、静态全局变量、静态局部变量、局部变量的区别
- python访问复数的实部,虚部和模值
- Eclipse 快捷键
- Oracle数据库imp/exp导入导出问题
- Django学习6:利用POST方式提交表单
- ACM常用C/C++函数
- node.js学习笔记之创建TCP客户端
- ubuntu 打开终端快捷键
- JAVA中日期类Date、日历类Calendar、DateFormat类
- hdu 6043 KazaQ's Socks
- cluster_state:fail error clusterdown hash slot not served redis集群启动失败 解决办法
- 数据类型转换
- XListView+ImageLoader+AsyncTask+网络获取数据综合