Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

mark_safe does not work in Django #217

Discussion options

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?

You must be logged in to vote

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

Comment options

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 %}
You must be logged in to vote
2 replies
Comment options

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

Comment options

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?

Comment options

Yep. That's right.

You must be logged in to vote
2 replies
Comment options

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.

Comment options

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

Answer selected by Archmonger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /