I'm trying to display the post.content in multiple lines. I tried to replace \r\n with
but it's still not working.
My request method:
title = request.form["title"]
content = request.form["content"]
# display the content response as multiple lines
content = content.replace("\r\n", " <br> ")
if content == "" or title == "":
return render_template("admin.html", title="Admin", user_authenticated=user_authenticated, error="Please fill in all fields.")
else:
user = User.query.filter_by(username=username).first()
post = Post(title=title, content=content, user_id= user.id )
db.session.add(post)
db.session.commit()
return redirect(url_for("index"))
How I display the content in the HTML:
<p>{{ post.content }}</p>
` and mark it as safe in your jinja statement: `{{ post.content | safe }}`. I would recommend the last one, as post params are user input and thus not safe to mark as safe without further checks. – ð᠍᠍ May 19 '22 at 18:34