On the ticket, Luke pointed out these libraries: 1) For Python code: urlobject https://github.com/zacharyvoase/urlobject/ and furl https://github.com/gruns/furl 2) For template code: django-spurl - https://github.com/j4mie/django-spurl
He doesn't see a need to include a subset of the functionality provided by these libraries in Django itself. I'm okay with that if it's the consensus but this brings up the question about to what extent the documentation should point to or endorse third-party packages. On Friday, October 23, 2015 at 11:18:38 AM UTC-4, Collin Anderson wrote: > > If it helps, I have a similar need in the template. My case requires > adding, removing, or replacing one of the arguments on the fly: > > In templates, I often need to change _one_ key of a GET request on the > fly. My use case is a "filter by" sidebar on the same page as a "sort by" > and "number per page". (Example: http://comcenter.com/category/BC020/ ). > > I currently use a simple custom template tag: > @register.simple_tag > def make_query(params, key=None, value=None): > from django.utils.http import urlencode > if key: > params = params.copy() > if value: > params[key] = value > else: > params.pop(key, None) > return '?' + urlencode(params, True) if params else '.' > > For previous/next pages, I simply use: > <a href="{% make_query request.GET "page" page.next_page_number %}"> > > For more complicated things, in the view I collect all of the valid params > and pass them to the template. (I don't keep the "page" key in "params", > because I want that to reset when filtering or sorting.) > <a href="{% make_query params "per_page" "24" %}"> > <a href="{% make_query params filter.field_name option.new_param %}"> > > I can remove keys like so: > <a href="{% make_query params filter.field_name "" %}">Show All</a> > > On Friday, October 23, 2015 at 3:41:42 AM UTC-4, guettli wrote: >> >> From https://code.djangoproject.com/ticket/25582 >> >> {{{ >> >> It is a common question on stackoverflow and other places: >> >> How to reverse() to url including GET parameters? Example: >> .../myview?foo=bar >> >> >> http://stackoverflow.com/questions/9585491/how-do-i-pass-get-parameters-using-django-urlresolvers-reverse >> >> http://stackoverflow.com/a/27641445/633961 >> >> It would be very nice if django could implement a short-cut which provides >> this. >> It would be useful for python code and template, too. >> }}} >> >> {{{ >> If we do add it, it likely needs a discussion on the >> DevelopersMailingList >> <https://code.djangoproject.com/wiki/DevelopersMailingList> to figure >> out what the API should look like. See also #10941 >> <https://code.djangoproject.com/ticket/10941> which asks for a template >> tag for creating query strings in templates. >> }}} >> >> What do you think? >> >> >> >> -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/0466688f-11b2-4c79-9d0f-3e4eb63afaa2%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
