Home > Django > Accepting NULL value in URL

Accepting NULL value in URL

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:
  1. No comments yet.
  1. No trackbacks yet.