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)