Opened 6 years ago

Last modified 6 years ago

#30038 closed New feature

New shortcut: redirect_with_params() — at Version 1

Reported by: agustin bacigalup Owned by: nobody
Component: Uncategorized Version: 2.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by agustin bacigalup)

I'd like to contribute to Django by adding a shorcut, similar to django.shortcuts.redirect but also appends request's GET parameters. I found myself using it a lot, and I wonder if it's useful for the community. If so, should I fork Django on Github and submit a pull request?

def redirect_with_params(request, to, *args, **kwargs):
    """
    Same as `django.shortcuts.redirect` but recieves a `request` as first parameter.
    It preserves the GET parameters from the `request` in the URL redirected.
    """
    response = redirect(to, *args, **kwargs)
    url = response.url
    params = request.GET.urlencode()
    if params:
        url = "%s?%s" % (response.url, params)
    return response.__class__(url)

Change History (1)

comment:1 by agustin bacigalup, 6 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top