我正在使用python 3.7 我的代码:
from flask import Flask, request
from flask.json import jsonify
import os
from flask_wtf import FlaskForm
app = Flask(__name__)
app.config.update(
DEBUG=True,
SECRET_KEY='This key must be secret!',
WTF_CSRF_ENABLED=False,
)
@app.route('/serve/files/filename', methods =['GET', 'POST'])
def show_file(filename):
if not os.path.exists('./serve/files/' + filename):
return '404: File doesnt exist'
else:
with open('./serve/files/' + filename, 'r') as f:
return f.read()
if __name__ == '__main__':
app.run()
我的GET请求127.0.0.1:5000/serve/files/one.txt
返回one.txt
但是我需要文件中的文本。
我怎么了?