本文介绍了蟒蛇烧瓶通过邮件和网址发送数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于通过POST通过CURL发送数据和通过URL发送数据的问题。更一般地说,我有一个烧瓶路线

  @ app.route('/ create',methods = ['POST']) 
def clone:
...

我怎样才能发送数据一个URL?我想这样做:



pre $ lt; code>< my-server>:port / create / arg1 / arg2 / arg3

我刚才发现你可以做一些类似于

  @ app.route( '/创建',方法= [ 'POST'])
@ app.route('/创建/< OP> /<信源> /< target>,methods = ['GET'])
def clone(op = None,source = None,target = None):
...

哪个会起作用。这是一个很好的方法吗?

解决方案

要访问实际的查询字符串( code $)使用:

$ p $ / create',methods = ['POST'])
def clone:
return request.query_string

访问已知的查询参数:

 来自瓶子导入请求

@app .route('/ create',methods = ['POST'])
def clone:
user = request.args.get('user')

如果你正在寻找像 / arg1 / arg2 / arg3 这样的变量,使用:

  @ app.route( '/创建/< ARG1> /< ARG2> /< ARG3>',方法= ['POST'])
def clone(arg1,arg2,arg3):
...


I have a question regarding sending data via a CURL through POST and sending data through the URL. More generally, I have a flask route

@app.route('/create', methods=['POST'])
def clone:
   ...

How can I also send data using a URL? I want to do something like this:

<my-server>:port/create/arg1/arg2/arg3

I just figured out you can do something like

@app.route('/create', methods=['POST'])
@app.route('/create/<op>/<source>/<target>', methods=['GET'])
def clone(op = None, source = None, target = None):
    ...

Which will work. Is this a good approach?

解决方案

To access the actual query string (everything after the ?) use:

from flask import request

@app.route('/create', methods=['POST'])
    def clone:
        return request.query_string

To access known query parameters:

from flask import request

@app.route('/create', methods=['POST'])
    def clone:
        user = request.args.get('user')

If you're looking to use variables sent like /arg1/arg2/arg3 use:

@app.route('/create/<arg1>/<arg2>/<arg3>', methods=['POST'])
    def clone(arg1, arg2, arg3):
        ...

这篇关于蟒蛇烧瓶通过邮件和网址发送数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 17:33