Extracting HTML front-end Code common factor (5)

Source: Internet
Author: User

Extracting HTML front-end Code common factor (5)

Note: this is an optimized HTML code that extracts the same parts of multiple HTML code into a template and only needs to write the changed HTML

1, take advantage of the properties of the third parameter of the Render method provided by Django

Pass in the dictionary parameter to the template; This property enables merging of duplicate HTML code and separating the display data

2, find the same format, copy the different HTML code

Use the {% for B in blocks%} and {% endfor%} packages to traverse the copy (copy to do blocks dictionary processing), different copy to use {{B. Key name}} way to invoke

The 3,views.py code--in the Render method--Adds a third parameter (type of a dictionary) Block_infos, which is used in the dictionary to match the HTML inside;

Extracting HTML front-end Code common factor (5)

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.