1

Possible Duplicate:
Capturing url parameters in request.GET

I'm designing a detail page of my website by using django, and set the Topic Url as following:

(r'd/\d+/$', 'xiangwww.detail.views.detail'),

the second argument is the ID of the topic. But when I fetch it following the guide of Django Book :

def detail(request,offset):
    print offset
    return render_to_response('detail.html')

The page "localhost:8000/d/1/" in shows the TypeError: detail() takes exactly 2 arguments (1 given)

It seems Django can't recognise what is offset in my views.py file, how to solve it?

Community
  • 1
  • 1
Wei Lin
  • 749
  • 2
  • 6
  • 9

2 Answers2

4

You need to capture the number, by putting it in a regular expression group:

(r'd/(\d+)/$', 'xiangwww.detail.views.detail'),

Without the (...) group, Django does not know about the captured number and cannot pass it to your view. See the URL Dispatch documentation:

To capture a value from the URL, just put parenthesis around it.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
0

You need to change url to accept offset as parameter e.g.

(r'd/(?P<offset>\d+/)$', 'xiangwww.detail.views.detail'),
Rohan
  • 52,392
  • 12
  • 90
  • 87