Before learning Django templates, I thought that, like many php template engines, it was implemented by caching file output and executing python code in the template. After reading the template, I found that it is similar to the front-end template and uses regular expressions. In order to better understand the design philosophy, I also referred to the templates in tornato, drupal, codeigniter, aceTemplate, and underscore.
Before learning Django templates, I thought that, like many php template engines, it was implemented by caching file output and executing python code in the template. After reading the template, I found that it is similar to the front-end template and uses regular expressions. In order to better understand the design philosophy, I also referred to the templates in tornato, drupal, codeigniter, aceTemplate, and underscore.
Before learning Django templates, I thought that, like many php template engines, it was implemented by caching file output and executing python code in the template. After reading the template, I found that it is similar to the front-end template and uses regular expressions.
To better understand the design philosophy, I also referred to the template design in tornato, drupal, codeigniter, aceTemplate, and underscore.
Django template features
There is an important assumption when designing a Django template: "you do not understand python when writing a template ". Therefore, you only need to write the basic logic structure (Judgment, loop, output variable, etc.) to tell him. It also avoids programmers from writing business logic into the template. When parsing a template, It is very similar to the front-end template. It also uses regular expressions to extract all the code parts and then parses them sequentially (the scope is constructed according to the actual situation during parsing) into html.
The template implementation in php is relatively simple, mainly through buffering the output stream. The template uses the normal php code. This is mainly because php files directly output text not included in the php tag. Therefore, php templates can directly execute php code.
Here we can see that there are two completely different design ideas. Django proactively sets limits on Template users and wants to implement a small template language on its own. Tornato, php templates, and front-end templates allow developers to minimize learning costs and gain great freedom. However, the main reason why front-end templates give developers great freedom is that html and front-end logic are almost all written by individuals.
2. Supports template nesting
3. support template inheritance
Summary
I think the following are interesting:
1. No matter which template is implemented, it does not actually have a dime relationship with html.
2. The speed must be the fastest direct cache output stream like php. After all, the template compilation step is saved. If the python statement generated by tornato is encapsulated as a function, it can be cached.
3. The implementation of the Django template may be related to the design philosophy of the entire framework. I have not read it yet, so I will not comment on it. But at least I have explained why in the book.
At the beginning, I started to learn python and Django. If something is wrong, I would like to thank you for your correction.