views:

348

answers:

2

Hi guys, i want to know, what is the best way to write in the URL.py, im asking bcz im trying to get the index in this way "www.example.com" with (r'',index) but when i try r'' all pages in the website are going to the home pages.

part of my code url.py :

(r'^index',homepages),
(r'',homepages),

Thanks :)

+6  A: 

Like this:

 #...
 (r'^$', index),
 #...
Brian R. Bondy
+1  A: 

Django URL matching is very powerful if not always as convenient as it could be. As Brian says, you need to use the pattern r'^$' to force your pattern to match the entire string. With r'', you are looking for an empty string anywhere in the URL, which is true for every URL.

Django URL patterns nearly always start with ^ and end with $. You could in theory do some fancy URL matching where strings found anywhere in the URL determined what view function to call, but it's hard to imagine a scenario.

Ned Batchelder