{% load staticfiles %} 和 {% load static %} 有什么区别 [英] What is the difference between {% load staticfiles %} and {% load static %}
问题描述
问题最重要的部分是主题.
The most important part of the question is in the topic.
我想知道哪种标签最适合哪种情况.此外......我找到了代码,它也使用了 {{STATIC_URL}}
包含在模板中的 settings.STATIC_URL
.
I am wondering what tag is best for which case. Moreover... I found code, that also use settings.STATIC_URL
included by {{STATIC_URL}}
in the templates.
我有点困惑.
推荐答案
内置static
模板标签链接[s]到STATIC_ROOT
中保存的静态文件".
The built-in static
template tag "link[s] to static files that are saved in STATIC_ROOT
".
staticfiles
contrib 应用程序的 static
模板标签使用配置的 STATICFILES_STORAGE
存储为给定的相对路径创建完整的 URL",这在使用非本地存储后端部署文件时特别有用".
The staticfiles
contrib app's static
template tag "uses the configured STATICFILES_STORAGE
storage to create the full URL for the given relative path", which is "especially useful when using a non-local storage backend to deploy files".
内置 static
模板标签的文档(链接到上面)有一个注释说使用 staticfiles
contrib 应用程序的 static
模板标记如果您有高级用例,例如使用云服务来提供静态文件",并给出了这样做的示例:
The built-in static
template tag's documentation (linked to above) has a note that says to use the staticfiles
contrib app's static
template tag "if you have an advanced use case such as using a cloud service to serve static files", and it gives this example of doing so:
{% load static from staticfiles %}
<img src="{% static "images/hi.jpg" %}" alt="Hi!" />
如果需要,您可以使用 {% load staticfiles %}
而不是 {% load static from staticfiles %}
,但后者更明确.
You could use {% load staticfiles %}
rather than {% load static from staticfiles %}
if you want, but the latter is more explicit.
这篇关于{% load staticfiles %} 和 {% load static %} 有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!