[Fixed]-Django URL.py and the index

31👍

Like this:

 #...
 (r'^$', index),
 #...

5👍

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.

Leave a comment