URL configuration and loose coupling in Python's Django framework

Source: Internet
Author: User
Now is a good time to point out the philosophy behind Django and URL configuration: the loose coupling principle. Simply put, loose coupling is an important software development method that guarantees interchangeability.

The Django URL configuration is a good example. In a Django application, the definition of the URL and the view function are loosely coupled, in other words, deciding which view function the URL returns and implementing this view function is in two different places. This allows the developer to modify a piece without affecting another piece.

For example, consider the Current_datetime view. If we want to change its URL from the original/time/to/currenttime/, we just need to quickly modify the URL configuration, do not worry 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 the corresponding URL.

In addition, if we want to output this function to some URLs, we just need to modify the URL configuration without having to change the view's code. In this example, Current_datetime is used by two URLs. This is a case in point, but this method will be used sooner or later.

Urlpatterns = Patterns ('  ^hello/$ ', hello), ('  ^time/$ ', current_datetime),  (' ^another-time-page/$ ') , Current_datetime),)
  • Related Article

    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.