Reputation: 345
I have followed a number of tutorials and read the following link from the Django docs. It is supposed to be good practice to use namespaced url's (e.g. 'polls:index') instead of hardcoding them.
I cannot fully understand why this is important, apart from convenience. Why exactly is this good practice and what problems could it help avoid?
https://docs.djangoproject.com/en/1.10/topics/http/urls/#url-namespaces
Upvotes: 1
Views: 129
Reputation: 59315
Your question is already answered in another section of the same documentation page (emphasis mine):
It is strongly desirable to avoid hard-coding these URLs (a laborious, non-scalable and error-prone strategy). Equally dangerous is devising ad-hoc mechanisms to generate URLs that are parallel to the design described by the URLconf, which can result in the production of URLs that become stale over time.
In other words, what’s needed is a DRY mechanism. Among other advantages it would allow evolution of the URL design without having to go over all the project source code to search and replace outdated URLs.
Upvotes: 1