The URL configuration and loose coupling in the Python Django framework, pythondjango
Now is a good time to point out the philosophy behind Django and URL configuration: loose coupling principle. To put it simply, loose coupling is an important software development method to ensure swapping.
Django URL configuration is a good example. In Django applications, the definition of a URL is loosely coupled with a view function. In other words, it determines which view function the URL returns and the implementation of this view function is in two different places. This allows developers to modify one item without affecting the other.
For example, consider the current_datetime view. If we want to change its URL from the original/time/to/currenttime/, we just need to modify the URL configuration quickly without worrying about the internal implementation of this function. Similarly, if we want to modify the internal implementation of this function, we do not have to worry about affecting the corresponding URL.
In addition, if we want to output this function to some URLs, we only need to modify the URL configuration without modifying the view code. In this example, current_datetime is used by two URLs. This is a mysterious example, but this method will be used sooner or later.
Urlpatterns = patterns ('', ('^ hello/$', hello), ('^ time/$', current_datetime ), ('^ another-time-page/$', current_datetime ),)