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. Objective-C的动态特性

    最近几年中涌现了大量的Objective-C开发者.有些是从动态语言转过来的,比如Ruby或Python,有些是从强类型语言转过来的,如Java或C#,当然也有直接以Objective-C作为入门语言 ...

  2. Ubuntu 14.04 编译newLISP 10.6.0

    1. 确保安装了gcc4.8.2 2. 安装须要的库: apt-get install libreadline6 libreadline6-dev 3. 下载并解压newLISP源码,这个不多说了,去 ...

  3. 几个常用的CSS3样式代码以及不兼容的解决办法

    原文:几个常用的CSS3样式代码以及不兼容的解决办法 border-radius实现圆角效果 CSS3代码: -webkit-border-radius:10px; -moz-border-radiu ...

  4. Java利用jcifs集成AD域用户认证

    近期一段时间发现AD这东西老火了,尤其是涉及到安全这一方面的,所以AD域用户认证成了如今网络安全方面的产品必备!这里就简单的分享一下,Java通过jcifs集成AD域用户实现认证,以实现网络安全! 我 ...

  5. Android开发之Mediaplayer

    Android提供了常见的音频.视频的编码.解码机制.借助于多媒体类MediaPlayer的支持,开发者能够非常方便在在应用中播放音频.视频.本篇博客主要解说在Android平台下怎样播放一个音频文件 ...

  6. 4. SQL Server数据库状态监控 - 作业状态

    原文:4. SQL Server数据库状态监控 - 作业状态 有很多地方可以设置定时任务,比如:Windows的计划任务,Linux下的crontab,各种开发工具里的timer组件.SQL Serv ...

  7. 记录一下Fedora21下安装Foundation5遇到的问题[尚有遗留问题]

    写在前面:之前安装过了gem,所以下面的步骤没有这一过程,再有就是忘记哪一步需要ruby中的一个.h文件.可以使用如下命令解决 sudo yum install ruby-devel ------ S ...

  8. Zend server最大化应用程序的性能、扩展性和可用性

    如果我有8个小时去砍到一棵树,我会花6个小时磨斧子”——林肯(美国总统) 你可以知道? 世界页面访问量的峰值超过7000万每分钟. CloudFare公司服务器问题,导致785000站点崩溃一小时. ...

  9. Oracle表介绍--簇表

    簇和簇表       簇其实就是一组表,是一组共享相同数据块的多个表组成. 将经常一起使用的表组合在一起成簇可以提高处理效率.       在一个簇中的表就叫做簇表.建立顺序是:簇→簇表→数据→簇索引 ...

  10. readonly和const的区别

    readonly与const的区别1.const常量在声明的同时必须赋值,readonly在声明时可以不赋值2.readonly只能在声明时或在构造方法中赋值(readonly的成员变量可以根据调用不 ...