Python 如何在基于flask的本地网站上发送GET/POST请求?

Python 如何在基于flask的本地网站上发送GET/POST请求?,python,html,python-3.x,rest,flask,Python,Html,Python 3.x,Rest,Flask,我有一个网站,通过上传按钮输入一个.txt文件。后端模型处理该文本文件并输出一个新的.txt文件。我的网站与用户界面完美配合。但是我尝试使用curl命令将GET/POST请求发送到我的文件: curl -F 'file=@CNN.txt' http://127.0.0.1:5000/ 结果是,我的整个html文件都在终端中打印(就像cat命令一样)。 我想知道如何使用curl命令本身获取已处理的文件?我认为要获取该文件,还需要返回某种JSON对象。我对这种东西完全陌生。请跟我说实话。。我的ap

我有一个网站,通过上传按钮输入一个.txt文件。后端模型处理该文本文件并输出一个新的.txt文件。我的网站与用户界面完美配合。但是我尝试使用curl命令将GET/POST请求发送到我的文件:

curl -F 'file=@CNN.txt' http://127.0.0.1:5000/
结果是,我的整个html文件都在终端中打印(就像cat命令一样)。 我想知道如何使用curl命令本身获取已处理的文件?我认为要获取该文件,还需要返回某种JSON对象。我对这种东西完全陌生。请跟我说实话。。我的appy.py文件是:

@app.route('/', methods = ['GET','POST'])
def hello():
    if(request.method == 'POST'):
        if('file' not in request.files):
            return 'NO FILE'
        file = request.files['file']
        if(file.filename == ''):
            print('NO FILES')
            return redirect(request.url)
        if(file and allowed_file(file.filename)):
            uploadedFile = file.filename
            file.save(os.path.join(UPLOAD_FOLDER, file.filename))
            if(uploadedFile != ''):
                neural_code_sum.starter(uploadedFile)
            return render_template('index.html', message='success')
    return render_template('index.html', message='NOT UPLOADED (ONLY .TXT FILES ALLOWED)')


@app.route('/download')
def download_file():
    global uploadedFile
    doc = os.path.dirname(os.path.realpath(__file__))+'/output.txt'
    return send_file(doc,as_attachment=True,cache_timeout=0)
只需在上面添加GET:

@app.route('/download', methods = ['GET'])
def download_file():
    global uploadedFile
    doc = os.path.dirname(os.path.realpath(__file__))+'/output.txt'
    return send_file(doc,as_attachment=True,cache_timeout=0)
第一个发送文件:
curl-F'file=@CNN.txt'http://127.0.0.1:5000/

然后下载它:
curlhttp://127.0.0.1:5000/download -o output.txt

就这样!祝您一切顺利。

只需在上面添加GET:

@app.route('/download', methods = ['GET'])
def download_file():
    global uploadedFile
    doc = os.path.dirname(os.path.realpath(__file__))+'/output.txt'
    return send_file(doc,as_attachment=True,cache_timeout=0)
@app.route('/download',methods=['**GET'**])
def download_file():
global uploadedFile
doc = os.path.dirname(os.path.realpath(__file__))+'/output.txt'
return send_file(doc,as_attachment=True,cache_timeout=0)
第一个发送文件:
curl-F'file=@CNN.txt'http://127.0.0.1:5000/

然后下载它:
curlhttp://127.0.0.1:5000/download -o output.txt

就这样!祝你一切顺利

@app.route('/download',methods=['**GET'**])
def download_file():
global uploadedFile
doc = os.path.dirname(os.path.realpath(__file__))+'/output.txt'
return send_file(doc,as_attachment=True,cache_timeout=0)
在“方法”字段中添加要用于发送请求的方法

在“方法”字段中添加要用于发送请求的方法