• 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,跟这个比较相似。一样的道理。 &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的话,那就是向服务器取得内容。就这么简单。

  • 相关阅读:
    递归调用简单的讲解
    有关杭电acm问题的分类
    【jquery】切换标题与内容/点击后动态切换当前状态
    将数组某键值抽出作为新数组
    table表格制作
    如何导入大sql文件到mysql数据库
    二维数组按照某一键值进行排序
    利用PHP输出某一目录所有文件
    php结合js动态获取空间时间
    ie6不支持minheight的解决方案
  • 原文地址:https://www.cnblogs.com/spaceship9/p/3152946.html
Copyright © 2020-2023  润新知