I had problems with regex in urls.py (I start with django as well as regexes)
Here is my original urls.py
url(r'^name/(?P<name>\w+)/$', 'course.views.name'), url(r'^', 'course.views.index'),
And I tried to access it using this:
http://127.0.0.1:8000/name/blah/
My view looks like this:
def index(request): return HttpResponse("Hello, sam. You're at the course index.") def name(request, name): return HttpResponse("Hello, %s. You're at the course index." % name)
The result that I got was that no matter what contribution I made, I would regularly get the "index" function, not the "name" function. I thought the problem was with the first regex.
But then I changed the second to:
url(r'^$', 'course.views.index'),
And IT works the way I thought it works!
I understand that "$" means the end of the line, but shouldn't the first regex be evaluated first? What is the order of matching of these expressions?
Adding "$" to each URL is not a big deal, but I would like to understand why I am posting it.
I am using Django1.4 and Python 2.7
Samudra
source share