[Django]-How to remove get parameter from url in django view

-1👍

I ended up doing a redirect instead. That removes the get parameter.

👤Atma

2👍

If I understand it well, once you’ve done the copy you want the page to be redirected so no more copy will be made. Do like this then:

...
if copy:
    the actual copy and then...
    return HttpResponseRedirect(redirect_to='/the-path-without-copy-parameter/')
...

Then you can improve your code:

  • add copy as an actual route parameter, def copy_group(request,
    copy=None)
  • generate the path in redirect_to instead of hardcoding it
  • Out of topic: add a functional test for it if there is none 🙂

BTW, I’m not sure why you use a Get parameter and not just a different URL for it??

Leave a comment