0

In my django app . I have endpoints for a package with the months like :

www.example.com/cart/packagename/months 

www.example.com/cart/stater/3

which i dont think will good as an url pattern I want something like :

www.example.com/cart/?package=stater&months=3

And also want to encode the parameters 'package=stater&months=3'

If anyone has any suggestions how to achieve that with django let me know. because before i worked with laravel and its pretty simple to do.

John
  • 301
  • 4
  • 12
  • Does this answer your question? [How to add url parameters to Django template url tag?](https://stackoverflow.com/questions/25345392/how-to-add-url-parameters-to-django-template-url-tag) – shaik moeed Feb 24 '20 at 05:43

1 Answers1

1

Its also very simple to do in Django. The part after question mark here is called URL Query String. You can get its value by:

def cart_view(request):
    packages = request.GET.get('package')
    months = request.GET.get('months')

As URL query string has nothing to do with actual URL, so you need to change your url.py to:

path('cart/', cart_view,name='cart_view'),
ruddra
  • 50,746
  • 7
  • 78
  • 101
  • How i will add this to the radio button of months like when 3 months will select it will auto refresh and load the prices of 3 months package . – John Feb 24 '20 at 06:07
  • You need to write some JS for that and unfortunately that is not in the scope of this question. Better to ask a new one :) – ruddra Feb 24 '20 at 06:23