@app.route('/tiji', methods=['POST']) def tiji(): dch = request.form.get('dch') name = request.form.get('filename') print(name) folder_name = f"{dch}dianyun" if not os.path.exists(folder_name): os.mkdir(folder_name) for file in request.files.getlist('file'): filename = file.filename file.save(os.path.join(folder_name, filename)) dhs = request.form.getlist('dh') print(len(dhs)) for i in range(len(dhs)): print(dhs[i]) folder_path = os.path.join(folder_name) file_name = f"{name}.laz" if has_file(folder_path, file_name): return jsonify({"code": 200, "msg": "success"}) else: return jsonify({"code": 500, "msg": "fail"}) print('hi') 用什么替换return jsonify,可以在发送success给前端后还可以打印hi
时间: 2023-12-13 20:02:48 浏览: 114
c++基础练习题及解答细节全解.docx
如果你想在发送成功响应给前端后打印 "hi",你可以使用 `print()` 函数并在最后使用 `return` 语句返回一个字符串给前端。这样可以同时在控制台打印消息并发送响应。
以下是修改后的代码示例:
```python
@app.route('/tiji', methods=['POST'])
def tiji():
dch = request.form.get('dch')
name = request.form.get('filename')
print(name)
folder_name = f"{dch}dianyun"
if not os.path.exists(folder_name):
os.mkdir(folder_name)
for file in request.files.getlist('file'):
filename = file.filename
file.save(os.path.join(folder_name, filename))
dhs = request.form.getlist('dh')
print(len(dhs))
for i in range(len(dhs)):
print(dhs[i])
folder_path = os.path.join(folder_name)
file_name = f"{name}.laz"
if has_file(folder_path, file_name):
print('hi') # 在此处打印 "hi"
return "success" # 返回一个字符串给前端
else:
return "fail" # 返回一个字符串给前端
```
在上面的代码中,我将 `return jsonify()` 替换为了 `return "success"` 和 `return "fail"`,这样就可以返回一个字符串给前端。同时,我在成功情况下添加了一个 `print('hi')` 语句,用来打印 "hi"。
希望这可以解决你的问题!如果还有其他问题,请随时提问。
阅读全文