Python烧瓶故意空响应 [英] Python Flask Intentional Empty Response
问题描述
一个简单的'返回无'产生:
< pre $ ValueError:View函数没有返回响应
应该是可能的,因为下面只是下载一个文件,并不呈现模板:
myString =文档的第一行
response = make_response(myString)
response.headers [Content-Disposition] =attachment; filename = myFile.txt
返回响应
$ c $ p>您正在响应请求,您的HTTP服务器必须返回 。 HTTP的空响应响应是 204 No Content
:
return ('',204)
请注意,将文件返回给浏览器不是 em>一个空的响应,与HTML响应不同。
Is there a way to return a response (from make_response() object or similar) with certain properties so that it doesn't render the page again and doesn't do anything else either. I am trying to run a code on the server without generating any output
A simple 'return None' produces:
ValueError: View function did not return a response
This should be possible because the following only downloads a file and doesn't render the template:
myString = "First line of a document"
response = make_response(myString)
response.headers["Content-Disposition"] = "attachment; filename=myFile.txt"
return response
Any help will be greatly appreciated!
解决方案 You are responding to a request, your HTTP server must return something. The HTTP 'empty response' response is 204 No Content
:
return ('', 204)
Note that returning a file to the browser is not an empty response, just different from a HTML response.
这篇关于Python烧瓶故意空响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!