John
John

Reputation: 319

Django url dispatcher using repath arguments

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.

Upvotes: 0

Views: 2815

Answers (1)

ruddra
ruddra

Reputation: 52018

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'),

Upvotes: 1

Related Questions