我有一个服务,当调用特定的端点时,它应该返回一个字符串。但当它发生时,文本会被返回,但所有的换行符"\n"都是字面上写的,而不是我的邮递员响应中的换行符。示例:"你好\nworld"被发送,并且我得到";你好\nworld"而不是"你好世界;我在这里看到了一些关于堆栈溢出的解决方案,但不知道如何实现。有些使用的html脚本似乎对python文件不起作用。我真的不明白。
根据此答案,使用<br>
或<br/>
而不是n
:
@app.route("/")
def test():
return "Hello<br>World!"
Hello
World!
与我在这里看到的所有答案不同,我找到了问题的答案。将">
"不起作用。解决我问题的方法是在我的文件中添加一个标头。
#code before
msg = (...) #what is to be returned
#create the variable where you will store the returned text
response = make_response(msg, 200)
#then you add the header to it
response.mimetype = "text/plain"
#then return
return response