Flask中的request和response

一.request

代码语言:javascript
复制
    from flask import request

请求相关信息

    # request.method  提交的方法
    # request.args  get请求提及的数据
    # request.form   post请求提交的数据
    # request.values  post和get提交的数据总和
    # request.cookies  客户端所带的cookie
    # request.headers  请求头
    # request.path     不带域名,请求路径
    # request.full_path  不带域名,带参数的请求路径
    # request.script_root  
    # request.url           带域名带参数的请求路径
    # request.base_url		带域名请求路径
    # request.url_root      域名
    # request.host_url		域名
    # request.host			127.0.0.1:500
    # request.files
    # obj = request.files['the_file_name']
    # obj.save(&#39;/var/www/uploads/&#39; + secure_filename(f.filename))</code></pre></div></div><h3 id="7sif8" name="%E4%BA%8C.response">二.response</h3><div class="rno-markdown-code"><div class="rno-markdown-code-toolbar"><div class="rno-markdown-code-toolbar-info"><div class="rno-markdown-code-toolbar-item is-type"><span class="is-m-hidden">代码语言:</span>javascript</div></div><div class="rno-markdown-code-toolbar-opt"><div class="rno-markdown-code-toolbar-copy"><i class="icon-copy"></i><span class="is-m-hidden">复制</span></div></div></div><div class="developer-code-block"><pre class="prism-token token line-numbers language-javascript"><code class="language-javascript" style="margin-left:0">    from flask import render_template
from flask import redirect
from flask import make_response
 # 响应相关信息
    # return &#34;字符串&#34;
    # return render_template(&#39;html模板路径&#39;,**{})
    # return redirect(&#39;/index.html&#39;)
    #return jsonify({&#39;k1&#39;:&#39;v1&#39;})

    # response = make_response(render_template(&#39;index.html&#39;))
    # response是flask.wrappers.Response类型
    # response.delete_cookie(&#39;key&#39;)
    # response.set_cookie(&#39;key&#39;, &#39;value&#39;)
    # response.headers[&#39;X-Something&#39;] = &#39;A value&#39;
    # return response
    return &#34;内容&#34;</code></pre></div></div>