2

How do django views parse url queries? For example, suppose I have a view that lists all of the users at

localhost:8000/users/

If I wanted to add my own pagination feature, without django's built in one, how would I handle

localhost:8000/users/?page=10

or

localhost:8000/users/?id=526

I know that this defies that traditional sense of pretty url's, but I feel that it is necessary at some points.

user1876508
  • 12,542
  • 21
  • 65
  • 105

2 Answers2

3

Use request.GET.get():

fallback_page_num = '1'
page = request.GET.get('page', fallback_page_num)
falsetru
  • 336,967
  • 57
  • 673
  • 597
1

Just give a look at the official documentation: URL Dispatcher

Or look at this: Capturing the URL parameters in request.GET

Community
  • 1
  • 1
Markon
  • 4,230
  • 1
  • 25
  • 39