Opened 3 years ago

Closed 2 years ago

Last modified 2 years ago

#33779 closed New feature (fixed)

Add an encoder parameter to django.utils.html.json_script().

Reported by: Claude Paroz Owned by: Hrushikesh Vaidya
Component: Utilities Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have a use case where I want to customize the JSON encoding of some values to output to the template layer. It looks like django.utils.html.json_script is a good utility for that, however the JSON encoder is hardcoded to DjangoJSONEncoder. I think it would be nice to be able to pass a custom encoder class.

By the way, django.utils.html.json_script is not documented (only its template filter counterpart is), would it be a good thing to add to the docs?

Change History (8)

comment:1 by Mariusz Felisiak, 3 years ago

Summary: Add an encoder parameter to django.utils.html.json_scriptAdd an encoder parameter to django.utils.html.json_script().
Triage Stage: UnreviewedAccepted

Sounds good, and yes, we should document django.utils.html.json_script().

comment:2 by Hrushikesh Vaidya, 2 years ago

Owner: changed from nobody to Hrushikesh Vaidya
Status: newassigned

comment:3 by Hrushikesh Vaidya, 2 years ago

PR
I'll also add docs for json_script() soon

comment:4 by Mariusz Felisiak, 2 years ago

Has patch: set
Needs documentation: set
Needs tests: set

comment:5 by Mariusz Felisiak, 2 years ago

Needs documentation: unset
Needs tests: unset
Triage Stage: AcceptedReady for checkin

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

In 0ee03a43:

Refs #33779 -- Doc'd django.utils.html.json_script().

comment:7 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

Resolution: fixed
Status: assignedclosed

In 72e41a0d:

Fixed #33779 -- Allowed customizing encoder class in django.utils.html.json_script().

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

In e40b7736:

[4.1.x] Refs #33779 -- Doc'd django.utils.html.json_script().

Backport of 0ee03a439b7016c068ab2e0c477d5c84f750a82c from main

Note: See TracTickets for help on using tickets.
Back to Top