Archive

Archive for March 10th, 2008

Accepting NULL value in URL

March 10th, 2008 No comments

Within my Django project I wanted to have a page within the site for example “/page”. For that site I want there to be an optional value the page can take. So any of the following examples are acceptable: “/page/1″, “/page/2″, “/page”

There are two ways to do this.

First way (which is probably the right way) is to use the urls.py to handle this logic, like this:


(r'^pages/$', 'my_messages', {'page': page}),
(r'^pages/(\d*)$', 'my_messages'),

The other way is to handle it within the view with the following check:

if page == u'':

Categories: Django Tags: