I want my user to be able to write, for example image1 and use a regex to recognize and replace that with an tag. I have it all working -- but when I pass the data to template for display I do so like this:
<div class="container">
<p>
{% articleTxt %}
</p>
</div>
ArticleTxt contains:
This is a test Article <img src="/media/articleImages/django-allauth.png">
and that was a picture and this is another one then some more text ----
original: This is a test Article *image1* and that was a picture and this is
another one *image2* then some more text
Thats my frustration. I've tried changing the template to:
{% autoescape off %} {{articleTXT}} {{% autoescape %}}
I also tried
{{% articleTXT|safe %}}
It always prints the tags instead of rendering them. Is there anyway to render tags embedded in text passed from views.py to my template!!
{{ articleTXT |safe }}
or
{% autoescape off %} {{ articleTXT }} {% endautoescape %}
should do the trick
*Note: its {% endautoescape %}
if that isnt working try,
format_html(articleTXT)
in your views.
Hope this helps :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.