The URL configuration and loose coupling in the Python Django framework, pythondjango

Source: Internet
Author: User

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 ),)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.