Opened 7 years ago
Closed 7 years ago
#30038 closed New feature (wontfix)
New shortcut: redirect_with_params()
| 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 )
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 (2)
comment:1 by , 7 years ago
| Description: | modified (diff) |
|---|
comment:2 by , 7 years ago
| Resolution: | → wontfix |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Hi Augustin,
If you look at
RedirectView, you'll see thequery_stringattribute. It might be good to mirror the variable name there.It also uses `request.META`'s `'QUERY_STRING`', which might save you a step:
args = self.request.META.get('QUERY_STRING', '') if args and self.query_string: url = "%s?%s" % (url, args)I can see how this might be a handy addition to a project. I'm not sure it merits an additional function in
shortcuts. (It doesn't seem in the same order of utility as the existing methods.redirect()itself is 9 or 10 years old, so we've been living without this for a while...) I guess for me it's the sort of thing that can happily live in a blog post or a gist or a third-party package (if it were bundled up with other things).Happy if you want to ask if there's appetite to include it on django-developers, but at this point I'll lean towards not. Thanks.