Skip to content

Django 5.1: use mark_safe for PrettyJSONWidget#34

Open
b0uh wants to merge 2 commits intokevinmickey:masterfrom
b0uh:fix/mark-safe-widget
Open

Django 5.1: use mark_safe for PrettyJSONWidget#34
b0uh wants to merge 2 commits intokevinmickey:masterfrom
b0uh:fix/mark-safe-widget

Conversation

@b0uh
Copy link
Copy Markdown

@b0uh b0uh commented Jun 3, 2024

After upgrading to Django 5.1 we notice that the PrettyJSONWidget was broken in the admin. It seems to be because the HTML code returned is not marked as safe.

I tested the behavior locally and also run the tests coming along the projects to be sure I was not breaking anything.

Before

Screenshot 2024-06-03 at 16 01 56

After

Screenshot 2024-06-03 at 16 01 23

@b0uh
Copy link
Copy Markdown
Author

b0uh commented Jun 3, 2024

If someone else has this issue, the following snippet is a temporary workaround:

from django.utils.safestring import mark_safe
from prettyjson import PrettyJSONWidget

class PrettyJSONWidgetFixed(PrettyJSONWidget):
    def render(self, name, value, attrs=None, **kwargs):
        return mark_safe(super().render(name, value, attrs=None, **kwargs))

@makulatur
Copy link
Copy Markdown

Would be nice to have this merged

minchinweb added a commit to minchinweb/minchin.django.excel that referenced this pull request Dec 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants