Assume that it urltakes an argument (here book_id) and passes the value to views:
url
book_id
views
url(r'^/(?P<book_id>\w+)/$', 'pro.views.book', name='book'),
Is it possible that url accepts an argument, but if no argument is given, take the default value. If possible, perhaps in viewstoo. I apologize if this is a lame question, but I really need to know. Any help or suggestion would be greatly appreciated. thank you
. :
url(r'^(?:(?P<book_id>\w+)/)?$', 'pro.views.book', name='book'),
:
def book(request, book_id='default'):
, URL , :
url(r'^(?P<book_id>\w+)/$', 'pro.views.book', name='book'), url(r'^$', 'pro.views.book', name='default_book'),
, . , .