[Answered ]-What is happening in this urlpatterns list of Python Django urls.py file?

2👍

I’m not sure why you’re surprised; you removed a parameter, and things went wrong. (Your first version might well have “worked” when you ran the server, but I doubt you could actually get to the URL.)

You are using an old version of Django. In this version, urlpatterns must be defined with the result of the patterns function. The first parameter to that function is a prefix to apply to all view strings. Your prefix is empty, but that doesn’t mean you can just remove it; your first URL is now being taken as the prefix parameter.

In recent versions it was recognised that this prefix is confusing and rarely used. As a result, the patterns function is removed and there is no prefix; the value of urlpatterns must now be a simple list. Additionally, views in urls must be callables, not strings.

Leave a comment