from flask import Flask, request, jsonify import os app = Flask(__name__) @app.route('/upload', methods=['POST']) def upload(): dch = request.form.get('dch') folder_name = f"{dch}duichang" if not os.path.exists(folder_name): os.mkdir(folder_name) for file in request.files.getlist('files'): filename = file.filename file.save(os.path.join(folder_name, filename)) return jsonify({"code": 200, "msg": "success"}) if __name__ == '__main__': app.run(host='192.168.1.226', port=7000)这段代码运行后run窗口会输出C:\Users\a212\AppData\Local\Programs\Python\Python36\python.exe D:\gangko\t1.py * Serving Flask app 't1' (lazy loading) * Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Debug mode: off * Running on http://192.168.1.226:7000/ (Press CTRL+C to quit),如何更改可以运行后没有WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.这段警告
时间: 2024-03-28 16:42:23 浏览: 196
可以在运行 Flask 应用程序时设置环境变量 `FLASK_ENV` 的值为 `production`,以便启用生产模式。修改代码如下:
```python
import os
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/upload', methods=['POST'])
def upload():
dch = request.form.get('dch')
folder_name = f"{dch}duichang"
if not os.path.exists(folder_name):
os.mkdir(folder_name)
for file in request.files.getlist('files'):
filename = file.filename
file.save(os.path.join(folder_name, filename))
return jsonify({"code": 200, "msg": "success"})
if __name__ == '__main__':
app.config['ENV'] = 'production'
app.run(host='192.168.1.226', port=7000)
```
这样运行代码后,就不会再输出 `WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.` 这段警告信息了。
阅读全文