除非我做錯了事情,看起來好像如果您有嵌套模板(即{% include %}
模板中的模板),您有時需要在多個「圖層」中調用{% load static %}
,的巢。例如,說我有templateA.html
:性能從加載Django靜態標籤多次點擊
{% load static %}
<a href={% static "some/path" %}>Some Link</a>
{% include 'templateB.html' %}
然後在`templateB.html,我有:
{% load static %}
<a href={% static "some/other/path" %}>Some Other Link</a>
據我可以從測試出來,我必須在兩個模板{% load static %}
,因爲templateB.html
不知道我已經加載了{% static %}
標籤。
我的問題是這樣的:
假設有必要加載{% static %}
標籤兩次(或根據嵌套的量更多次),有沒有打算從這個額外的裝載性能的下降?
我不確定Django在加載這個標籤時會做些什麼,但我的直覺是你不想加載和重新加載靜態文件。 (因爲我們正在談論一個開源項目,我確實嘗試了嘗試來看看這個templatetag
是如何實現的,但事實證明這有點超出我的理解......)。
此外,這個問題假設有必要總是以這種方式加載標籤。如果有什麼我錯過了,我會非常有興趣瞭解更多。謝謝!