-1

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>
ð᠍᠍
  • 870
  • 8
  • 16
  • You either have to iterate over your splitted content or replace newlines with `
    ` 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
  • Sorry, meant to say: I would **not** recommend the last one due to possible security issues. – ð᠍᠍ May 19 '22 at 18:48
  • Could you code the first option out, I don't really know how to do it, sorry. – jan_lampert May 19 '22 at 18:55

0 Answers0