使用bottle进行web开发(2):http request
我们知道,http request有多个方法,比如get,post,delete,patch,put等。对用的,bottle都定义了相应的装饰器,目前定义了五个:
get(),post(),put(),delete(),patch()
post主要用于form的submit等,这里举例如下,先定义get:
from bottle import Bottle,run,template,request
@app.get('/login')
def login():
return '''<form action="/login" method="post">
Username: <input name="username" type="text" />
Password: <input name="password" type="password" />
<input value="Login" type="submit" />
</form>'''
这段代码运行后,会出来页面,但是提交的时候,会出错,提示没有相应的处理办法,增加对应的post处理方法:
@app.post('/login')
def do_login():
username=request.forms.get('username')
password = request.forms.get('password')
if(username=='wcf'):
return "<p>welcome wcf</p>"
else:
return "<p>Login failed.</p>"
后续会对request.forms做更详细的额介绍
使用bottle进行web开发(2):http request的更多相关文章
- Web开发-Servlet&HTTP&Request
<!doctype html>02 - JavaEE - Servlet&HTTP&Request figure:first-child { margin-top: -20 ...
- 使用bottle进行web开发(9):文件上传;json传递
1.文件上传 如果要完成文件上传,则需要对上文的form做一点改动,具体如下: <form action="/upload" method="post" ...
- 使用bottle进行web开发(8):get的参数传递,form里的额数据传递等
1.诸如:forum?id=1&page=5这样的,在bottle里,可以通过request.query来访问这些值,举例如下: from bottle import Bottle,run,r ...
- 使用bottle进行web开发(1):hello world
为什么使用bottle?因为简单,就一个py文件,和其他模块没有依赖,3000多行代码. http://www.bottlepy.org/docs/dev/ 既然开始学习,就安装它吧. pip3 in ...
- 使用bottle进行web开发(5):Generating Content
在纯粹的 WSGI中,你的应用能返回的数据类型是十分有限的,你必须返回可迭代的字符串,你能返回字符串是因为字符串是可以迭代的,但是这导致服务器将你的内容按一字符一字符的传送,这个时候,Unicode ...
- 使用bottle进行web开发(4):HTTPError
from bottle import error @error(404) def error404(error): return 'Nothing here, sorry' 上述代码,是对404的定义 ...
- 使用bottle进行web开发(6):Response 对象
Response的元数据(比如http的status code,headers,cookies等,都被i封装到一个叫Response的对象中,并传给浏览器. status code:status co ...
- 使用bottle进行web开发(3):静态文件的获取
静态文件(比如css啊,需要下载的各位文件等),需要通过static_file来操作,首先记得要在import中导入 @route('/static/<filename>') def se ...
- python bottle框架(WEB开发、运维开发)教程
教程目录 一:python基础(略,基础还是自己看书学吧) 二:bottle基础 python bottle web框架简介 python bottle 框架环境安装 python bottle 框架 ...
随机推荐
- textView代码设置文字居中失效 textView设置文字居中两种方法
1.TextView的高度占据整个父控件的高度,然后设置TextView的Grayvity Center就可以了. 2.如果第一个方法不行,那么,textView的高度设置为warp_content, ...
- qq登录面板
- 用 Flask 来写个轻博客
用 Flask 来写个轻博客 用 Flask 来写个轻博客 (1) — 创建项目 用 Flask 来写个轻博客 (2) — Hello World! 用 Flask 来写个轻博客 (3) — (M)V ...
- runtime怎么添加属性、方法等
ivar表示成员变量 class_addIvar class_addMethod class_addProperty class_addProtocol class_replaceProperty
- navmesh自动寻路
一个导航网格(也就是Navmesh)是世界几何体简化的表示法,被游戏代理用于在世界中进行导航.通常,代理(agent )有一个目标,或一个目的地,它试图找到一个路径,然后沿路径导航到达目标.这个过程被 ...
- CodeForces-1061B Views Matter
题目链接 https://vjudge.net/problem/CodeForces-1061B 题面 Description You came to the exhibition and one e ...
- CodeForces B. Creating the Contest
http://codeforces.com/contest/1029/problem/B You are given a problemset consisting of nn problems. T ...
- jQuery选择器之元素选择器
元素选择器:根据给定(html)标记名称选择所有的元素. 描述: $('element') 搜索指定元素标签名的所有节点,这是一个合集的操作.同样的也有原生方法getElementsByTagName ...
- Java进行身份证格式强校验(准)
最近做了一个系统,涉及到对用户输入的身份证号进行校验,减少脏数据传入后台处理并降低企业验证成本,因此在接入层便对输入信息做格式强校验. 直接附上代码,可直接使用. package hope.ident ...
- favicon.ico generator
favicon.ico generator https://www.favicon-generator.org/ https://www.favicon.cc/ https://www.favicon ...