Python Django TemplateSyntaxError - 'staticfiles' 不是注册的标签库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/55929472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Django TemplateSyntaxError - 'staticfiles' is not a registered tag library
提问by Alasdair
After upgrading to Django 3.0, I get the following TemplateSyntaxError
:
升级到 Django 3.0 后,我得到以下信息TemplateSyntaxError
:
In template /Users/alasdair//myproject/myapp/templates/index.html, error at line 1
'staticfiles' is not a registered tag library. Must be one of: admin_list admin_modify admin_urls cache i18n l10n log static tz
Here is my template
这是我的模板
{% load staticfiles %}
<img src="{% static 'my_image.html' %}">
回答by Alasdair
{% load staticfiles %}
and {% load admin_static %}
were deprecated in Django 2.1, and removed in Django 3.0.
{% load staticfiles %}
并在 Django 2.1 中{% load admin_static %}
被弃用,并在 Django 3.0 中删除。
If you have any of the following in your template:
如果您的模板中有以下任何一项:
{% load staticfiles %}
{% load static from staticfiles %}
{% load admin_static %}
You should replace the tag with simply:
您应该简单地替换标签:
{% load static %}
回答by Ehsan Barkhordar
In Django 3.0 you should use below tag instead:
在 Django 3.0 中,你应该使用下面的标签:
{% load static %}
回答by Sanjaya Bir Bikram Shrestha
It's due to upgrading to Django3.0, use as mentioned above.
由于升级到Django3.0,使用如上所述。
{% load static %}