如何编写Python代码实现生成并自动下载文件的后端功能?
- 内容介绍
- 文章标签
- 相关推荐
本文共计380个文字,预计阅读时间需要2分钟。
文本文件+生成并下载txt文件:+@app.route('/download', methods=['GET'])def download(): content='长文本' response=make_response(content) response.headers['Content-Disposition']='attachment; filename=myfilename.txt' return response
txt文件
生成并下载txt文件:
@app.route('/download', methods=['GET']) def download(): content = "long text" response = make_response(content) response.headers["Content-Disposition"] = "attachment; filename=myfilename.txt" return response
运行app.py后,在浏览器中输入:127.0.0.1:5000/download,直接下载txt文件。
本文共计380个文字,预计阅读时间需要2分钟。
文本文件+生成并下载txt文件:+@app.route('/download', methods=['GET'])def download(): content='长文本' response=make_response(content) response.headers['Content-Disposition']='attachment; filename=myfilename.txt' return response
txt文件
生成并下载txt文件:
@app.route('/download', methods=['GET']) def download(): content = "long text" response = make_response(content) response.headers["Content-Disposition"] = "attachment; filename=myfilename.txt" return response
运行app.py后,在浏览器中输入:127.0.0.1:5000/download,直接下载txt文件。

