I have a service that should return a string when a specific endpoint is called. But when it happens, the text is returned, but all the line jumpes '\n' are literally written instead of represent line jumps in my postman response. Ex.: "hello\nworld" is sent and I get "hello\nworld" instead of "hello world" I've seen some solutions here on the stack overflow, but didn't understand how to implement it. Some use html scripts that seem not work on the python file. I really didn't understand.
CodePudding user response:
As per this answer use <br>
or <br/>
instead of \n
:
@app.route("/")
def test():
return "Hello<br>World!"
Hello
World!
CodePudding user response:
Different from all the answers i've seen here, i found the answer to my question. Putting "
" doesn't work. What solved my problem was to add a header in my file.
#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