Bottle GET method. Request
python
bottle framework
#!/usr/bin/python
# -*- coding utf-8 -*- from bottle import route, run, debug, request
#from cgi import escape @route('/hello', method='GET')
def hello():
name = request.GET.get('name')
if not name:
name = "This guy's unknow :("
return 'Hello {0}'.format(name) debug(True)
run(host='localhost', port=8080, reloader=True)
Now I add a route here which is the
'/hello'
and I define the method to be 'GET'
And the request has request.GET.get('name')
then
name will be assigned again
All the def will return
return 'hello {0}'.format(name)
The reloader means the server will restart when it finds any files has been changed.


如果有注释掉前面的那句的话。
#from cgi import escape
可以出现下面的结果:

现在我们加上这个cgi的escape,目的是为了不让浏览器地址栏里的内容自动检索内容。
<h1></h1>标签
让我们大家来看看效果

看到了地址栏里面就没有继续在parse html代码了。
看看html代码内部的源码是:

非解析的html代码,这里曾经学习过php,跟这个比较相似。一样的道理。 < > 标签。
And if the method is POST
check those codes out:
#!/usr/bin/python
# -*- coding utf-8 -*- from bottle import route, run, debug, request
#from cgi import escape @route('/hello', method='POST')
def hello():
name = request.POST.get('name')
if not name:
name = "This guy's unknow :("
return 'Hello {0}'.format(name) debug(True)
run(host='localhost', port=8080, reloader=True)
实际上POST与GET没有什么区别。
只是在判断上有区别,判断一下,post可以让服务器修改一些内容,如果是get的话,那就是向服务器取得内容。就这么简单。
Bottle GET method. Request的更多相关文章
- sencha touch Ext.Ajax.request 错误 Cannot call method 'request' of undefined 解决方案
凡是Cannot call method '' of undefined 这类错误大部分都可以参照下面的办法来解决 在st中有时候你会发现使用Ext.Ajax.request会出现一下错误: Cann ...
- 使用bottle进行web开发(2):http request
我们知道,http request有多个方法,比如get,post,delete,patch,put等.对用的,bottle都定义了相应的装饰器,目前定义了五个: get(),post(),put() ...
- Python自动化运维之29、Bottle框架
Bottle 官网:http://bottlepy.org/docs/dev/index.html Bottle是一个快速.简洁.轻量级的基于WSIG的微型Web框架,此框架只由一个 .py 文件,除 ...
- Bottle 中文文档
译者: smallfish (smallfish.xy@gmail.com) 更新日期: 2009-09-25 原文地址: http://bottle.paws.de/page/docs (已失效) ...
- Recipes — Bottle 0.13-dev documentation
Recipes - Bottle 0.13-dev documentation Recipes¶ This is a collection of code snippets and examples ...
- 用Bottle开发web程序(一)
Bottle Bottle是一个轻量级的web app框架.相较与django等框架,bottle几乎没有任何依赖,而且只有一个文件.而相对于python默认的SimpleHTTPServer,功能更 ...
- bottle源码
import sys __author__ = 'Marcel Hellkamp' __version__ = '0.13-dev' __license__ = 'MIT' ############# ...
- bottle框架剖析
bottle框架剖析 使用 源码分析 一.使用 大致有以下几部分 quick start request routing generate contents request Data template ...
- python之Bottle框架
一.简单的Bottle框架 1)bottle框架简介 安装 pip install bottle Bottle是一个快速.简洁.轻量级的基于WSIG的微型Web框架. 此框架只由一个 .py 文件,除 ...
随机推荐
- HDU 4324 Triangle LOVE 拓扑排序
Problem Description Recently, scientists find that there is love between any of two people. For exam ...
- [Unity3D]Unity3D连衣裙实现游戏开发系统
大家好,我是秦培.欢迎关注我的博客,我的博客地址">blog.csdn.net/qinyuanpei. 不知从什么时候開始,国产RPG单机游戏開始出现换装,仙剑系列中第一部实现了换装的 ...
- effective C++ 札记 规定17 在单独的陈述newed对象插入智能指针
// Test.cpp : 自定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #include &l ...
- .NET 开源了,Visual Studio 开始支持 Android 和 iOS 程序编写并自带 Android 模拟器
.NET 开源了,Visual Studio 开始支持 Android 和 iOS 程序编写并自带 Android 模拟器 北京时间今天凌晨的 Connect(); 大会上,多少程序员的假想成为现实. ...
- 《Visual Studio Magazine》2013年读者选择奖—软件类
<Visual Studio Magazine>会在每年的下半年向读者发出投票邀请,读者将在28个大类,超过500个开发工具的名单中选出他们认为最好的产品,以票数评出各分类的金.银.铜奖. ...
- js 模拟QQ聊天窗口图片播放效果(带滚轮缩放)
页面效果如下: 完整代码如下: <!DOCTYPE html> <html> <head> <title>Test</title> < ...
- ComponentName意思
ComponentNameActivity Intent i=new Intent(); i.setComponent(new ComponentName(String packageName,Str ...
- python进程池剖析(二)
之前文章中介绍了python中multiprocessing模块中自带的进程池Pool,并对进程池中的数据结构和各个线程之间的合作关系进行了简单分析,这节来看下客户端如何对向进程池分配任务,并获取结果 ...
- div高度自适外层div高度随里层div高度自适
尝试过许多办法 其中一网友的最靠谱就是在外层div样式添加两个标签(不能少) clear:both; overflow:auto;
- ASP.NET MVC 5项目
图文详解远程部署ASP.NET MVC 5项目 话外篇: 由于感觉自己的机器比较慢,配置不好,所以最近想把之前的项目部署到实验室的服务器上,但是由于常不在实验室,所以在想能不能远程部署.因此今天专 ...