zoukankan      html  css  js  c++  java
  • 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的话,那就是向服务器取得内容。就这么简单。

  • 相关阅读:
    Win10 VS2013 PCL1.8.1和依赖项VTK8.0.1, QHuall(2.15.2), FLANN1.9.1,Boost1.59.0,Zbil1.2.11和libPNG1.6.34编译安装
    Boost log中的几个问题
    Linux 使用静态库注意事项
    Windows中lib和DLL区别和使用
    CMake: ELF文件加载动态库的位置
    CMake 默认编译、链接选项
    ld 链接选项-L,-rpath-link,-rpath
    动态库的链接和链接选项-L,-rpath-link,-rpath
    Linux共享对象之编译参数 -fPIC
    ny509 因子和阶乘
  • 原文地址:https://www.cnblogs.com/spaceship9/p/3152946.html
Copyright © 2011-2022 走看看