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,跟这个比较相似。一样的道理。 &lt;     &gt;  标签。

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的更多相关文章

  1. sencha touch Ext.Ajax.request 错误 Cannot call method 'request' of undefined 解决方案

    凡是Cannot call method '' of undefined 这类错误大部分都可以参照下面的办法来解决 在st中有时候你会发现使用Ext.Ajax.request会出现一下错误: Cann ...

  2. 使用bottle进行web开发(2):http request

    我们知道,http request有多个方法,比如get,post,delete,patch,put等.对用的,bottle都定义了相应的装饰器,目前定义了五个: get(),post(),put() ...

  3. Python自动化运维之29、Bottle框架

    Bottle 官网:http://bottlepy.org/docs/dev/index.html Bottle是一个快速.简洁.轻量级的基于WSIG的微型Web框架,此框架只由一个 .py 文件,除 ...

  4. Bottle 中文文档

    译者: smallfish (smallfish.xy@gmail.com) 更新日期: 2009-09-25 原文地址: http://bottle.paws.de/page/docs (已失效) ...

  5. Recipes — Bottle 0.13-dev documentation

    Recipes - Bottle 0.13-dev documentation Recipes¶ This is a collection of code snippets and examples ...

  6. 用Bottle开发web程序(一)

    Bottle Bottle是一个轻量级的web app框架.相较与django等框架,bottle几乎没有任何依赖,而且只有一个文件.而相对于python默认的SimpleHTTPServer,功能更 ...

  7. bottle源码

    import sys __author__ = 'Marcel Hellkamp' __version__ = '0.13-dev' __license__ = 'MIT' ############# ...

  8. bottle框架剖析

    bottle框架剖析 使用 源码分析 一.使用 大致有以下几部分 quick start request routing generate contents request Data template ...

  9. python之Bottle框架

    一.简单的Bottle框架 1)bottle框架简介 安装 pip install bottle Bottle是一个快速.简洁.轻量级的基于WSIG的微型Web框架. 此框架只由一个 .py 文件,除 ...

随机推荐

  1. .net中用Action等委托向外传递参数

    原文:.net中用Action等委托向外传递参数      一般我们可以使用ref,out达到向外传递参数目的. Action<T>是一个特殊的委托,除了常规应用.我们还可以用它来实现简单 ...

  2. 2014阿里巴巴研发project师暑期实习生面试经验

    2014阿里巴巴研发project师暑期实习生面试经验 作者:林子 Blog:  http://blog.csdn.net/u013011841 时间:2014年8月 出处:http://blog.c ...

  3. MVC生成CheckBoxList并对其验证

    原文:MVC生成CheckBoxList并对其验证 通过扩展方法,可以让CheckBox水平排列,生成CheckBoxList,正如"MVC扩展生成CheckBoxList并水平排列&quo ...

  4. Codeforces 113A-Grammar Lessons(实现)

    A. Grammar Lessons time limit per test 5 seconds memory limit per test 256 megabytes input standard ...

  5. sdut 3-4 长方形的周长和面积计算

    3-4 长方形的周长和面积计算 Time Limit: 1000MS Memory limit: 65536K 标题叙述性说明 通过本题的练习能够掌握拷贝构造函数的定义和用法: 设计一个长方形类Rec ...

  6. STL源代码分析——STL算法sort排序算法

    前言 因为在前文的<STL算法剖析>中,源代码剖析许多,不方便学习,也不方便以后复习.这里把这些算法进行归类,对他们单独的源代码剖析进行解说.本文介绍的STL算法中的sort排序算法,SG ...

  7. angular.js的路由和模板在asp.net mvc 中的使用

    angular.js的路由和模板在asp.net mvc 中的使用 我们知道angular.js是基于mvc 的一款优秀js框架,它也有一套自己的路由机制,和asp.net mvc 路由不太一样.as ...

  8. C/C++中常量字符串管理

    为了节省内存,C/C++把常量字符串放到单独的一个内存区域.当几个指针赋值给相同的常量字符串时,它们实际上会指向相同的内存地址.但用产量初始化字符数组,结果却不同. 下面是一个小程序示例: #incl ...

  9. JS字符串数字互转

    JS是一种弱类型的脚本语言,为变量赋值是会自动转换为相应的类型,例如: var a = 1; alert(a + 1);//结果为2 自动识别为数字类型进行数学运算 var b = '1'; aler ...

  10. 基于EF+MVC+Bootstrap的通用后台管理系统及架构

    分享基于EF+MVC+Bootstrap的通用后台管理系统及架构 基于EF+MVC+Bootstrap构建通用后台管理系统,集成轻量级的缓存模块.日志模块.上传缩略图模块.通用配置及服务调用, 提供了 ...