-
-
Notifications
You must be signed in to change notification settings - Fork 22
mark_safe does not work in Django #217
-
Hi,
the Django function mark_safe, nor the template | safe work with components. I am not able to save html in the database and display it in a component. Is there any possibility to add support for this, or is there a work around?
Beta Was this translation helpful? Give feedback.
All reactions
I'm going to assume your html strings are already escaped prior to entering the template and/or ReactPy.
If you want to unescape them, you can use html.unescape
Replies: 2 comments 4 replies
-
Just transferred this discussion to the reactpy-django repo.
Admittedly I haven't tried using Django template filters with our template tag. Are you trying to use them like this?
{% component "example.path" "<div> Hello World </div>" | safe %}
Beta Was this translation helpful? Give feedback.
All reactions
-
Yes, it doesn't work for me that way. It also doesn't work if you wrap the value in mark_safe(). https://docs.djangoproject.com/en/5.0/ref/utils/#module-django.utils.safestring
Beta Was this translation helpful? Give feedback.
All reactions
-
Alright I'll check this later tonight. What kind of output do you get if you use the safe filter?
Is it the HTML content with escape characters?
Beta Was this translation helpful? Give feedback.
All reactions
-
Yep. That's right.
Beta Was this translation helpful? Give feedback.
All reactions
-
I might need more information on how to reproduce your issue.
I've confirmed in #219 that HTML string objects and template tag strings are passed as literals, so they don't need any usage of safe or mark_safe.
Beta Was this translation helpful? Give feedback.
All reactions
-
I'm going to assume your html strings are already escaped prior to entering the template and/or ReactPy.
If you want to unescape them, you can use html.unescape
Beta Was this translation helpful? Give feedback.