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. nexus私服linux搭建问题

    一.最近搭建nexus私服,从官网下载下来总是报503服务器无效,很是无奈,最后在网上找到一个可以用的 收藏起来,这里给大家共享一下 下载地址:http://pan.baidu.com/s/1kT3U ...

  2. request.getparameter和 request.getattribute的差别

    request.getAttribute():是request时设置的变量的值,用request.setAttribute("name","您自己的值");来设 ...

  3. PHP 8: PHP的运算符

    原文:PHP 8: PHP的运算符 本章将介绍PHP的运算符.运算符这个问题在每种语言里都有,因为我们已经熟悉了编程语言里的一种或是多种,所以只需要了解一下就行了.概括一下吧.PHP运算符有很多种,看 ...

  4. 笔试题&amp;面试题:CW输出矩阵

    称号:CW输出矩阵(N*N). 如果一个矩阵: 1   2   3   4 5   6   7   8 9  10 11 12 13 14 15 16 那么程序应该给出的输出为:1 2 3 4 8 1 ...

  5. DynamicResource与StaticResource的区别

    原文:DynamicResource与StaticResource的区别 2008-06-20 12:16:12 静态资源在第一次编译后即确定其对象或值,之后不能对其进行修改.动态资源则是在运行时决定 ...

  6. 异步陷阱之IO

    异步陷阱之IO篇 很多教程和资料都强调流畅的用户体验需要异步来辅助,核心思想就是保证用户前端的交互永远有最高的优先级,让一切费时的逻辑通通放到后台,等到诸事完备,通知一下前端给个提示或者继续下一步.随 ...

  7. .Net下简单地实现MD5加密

    在.Net中为我们提供了一个方法HashPasswordForStoringInConfigFile,可以简单方便地实现MD5加密.该方法位于System.Web命名空间下,所以需要在引用中添加Sys ...

  8. iScroll 4.2.5 中文API

    概况 资料来源 http://cubiq.org/iscroll-4 http://www.cnblogs.com/wanghun/archive/2012/10/17/2727416.html ht ...

  9. bash下几个替换运算符的区分

    bash下几个替换运算符的区分 2012-03-21 22:20:54 分类: Python/Ruby 一直对四个替换运算符比较的迷惑,分布太清楚,记下来避免再次遗忘:   ${name:-word} ...

  10. 博客加上“Fork me on Github”彩带

    给你的博客加上“Fork me on Github”彩带 起 如今,随着Git的大热以及Github的优越性,许多知名开源项目都将源代码托管到Github上了.在Github上不仅可以托管自己的开源项 ...