Skip to content

django.urls.reverse(): Add option to prevent escaping query params #29

Open
@roniemartinez

Description

@roniemartinez

Code of Conduct

  • I agree to follow Django's Code of Conduct

Feature Description

We have migrated to 5.2 and loved the query param in reverse(). Thanks for adding this feature.

We recently encountered a limitation with this feature preventing us from using "unescaped" characters in the URL. For example in Stripe checkout (see https://docs.stripe.com/payments/checkout/custom-success-page?locale=en-GB), we need curly braces in the URL but this is being url-encoded in reverse().

Problem

Internally, reverse() uses urllib.parse.urlencode() as described in the documentation. The current implementation is not allowing "unescaped" characters like curly braces.

>>> urllib.parse.urlencode(query={"session_id": "{CHECKOUT_SESSION_ID}"})
'session_id=%7BCHECKOUT_SESSION_ID%7D' 

What we want (as Stripe's doc says) is to have unescaped curly braces. This can be obtained in urlencode with safe param as:

>>> urllib.parse.urlencode(query={"session_id": "{CHECKOUT_SESSION_ID}"}, safe="{}")
'session_id={CHECKOUT_SESSION_ID}'

Request or proposal

request

Additional Details

No response

Implementation Suggestions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Idea

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions