Output HTML as HTML in Askama (Actix-web)

I have HTML saved in my database and I want to output it in an Askama template using Actix-web.

This is my basic Actix-code:

let mut s = Page {
        html_content: "<p>test</p>".to_string(),
    }
    .render()
    .unwrap();

    Ok(HttpResponse::Ok().content_type("text/html").body(s))

This is in the template of Page:
{{ html_content }}

Output: <p>test</p>/

I also tried:

{% raw %}
    {{ html_content }}
{% endraw %}

and that outputs {{ html_content }}.

So what is the correct way to do this? Thanks.

You can do the following:

{{ html_content|safe }}

Using |safe (without spaces) marks the variable in Askama safe for raw HTML-outputting.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.