python - Flask中extends与import的区别?
PHP中文网
PHP中文网 2017-04-18 09:25:37
0
3
503

《Flask web development》示例4-3中,使用Flask-WTF和Flask-Bootstrap渲染表单

{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}

想问下什么情况下用extends什么情况下用import?两者有什么区别?

PHP中文网
PHP中文网

认证0级讲师

reply all(3)
巴扎黑

Let me make a note:
extendThe main purpose of inherited templates is for sub-templates to reference its structure and supplement the block content in it.

import引用的模板主要为了在子模板中引用它的变量,宏函数等。类似import osThis way, you can also define macro functions with the same name. bootstrap/wtf.html source code

The subject’s question link on stackoveflow: what are the differences between import and extends in Flask?

洪涛

extends means inheritance, import means reference. Inheritance can change the original content, but reference cannot

迷茫

extends are generally used in template calls. For example, the content in your base.html is the main frame of the web page, with buttons, navigation, etc. at the top.
And in other pages, such as xxxxx.html, the basic frame is the same. , and you only need to modify the content of the page, then you don’t have to rewrite the code of the main frame in xxxxx.html every time, and you can “copy” the main frame by inheriting from base.html

And import is generally used to reference modules or functions
For example, the import os that we usually use most
is to introduce the standard os module

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template