[英]Django TemplateSyntaxError - 'staticfiles' is not a registered tag library
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' %}">
If you have any of the following tags in your template:如果您的模板中有以下任何标签:
{% load staticfiles %}
{% load static from staticfiles %}
{% load admin_static %}
Then replace it with:然后将其替换为:
{% load static %}
You have to make this change because {% load staticfiles %}
and {% load admin_static %}
were deprecated in Django 2.1 , and removed in Django 3.0 .您必须进行此更改,因为
{% load staticfiles %}
和{% load admin_static %}
在 Django 2.1 中已弃用,并在 Django 3.0 中删除。
{% load static %}
instead of {% load staticfiles %}
{% load static %}
而不是{% load staticfiles %}
settings.py
filesettings.py
文件末尾写入以下行STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
VENV_PATH = os.path.dirname(BASE_DIR)
STATIC_ROOT = os.path.join(VENV_PATH, 'static_root')
This worked for me using django 3.1.4.这对我使用 django 3.1.4 有用。
{% load static %}
<link rel"stylesheet" href = "{% static 'style.css' %}">
its working for me它为我工作
this worked with me replace {% load static from staticfiles %}
with {% load static %}
这对我有用,用
{% load static %}
替换{% load static from staticfiles %}
}
where:在哪里:
go to your virtual environment "venv" /lip/python3.X/site-packages/leaflet/templates/leaflet/admin/widget.html and all of the.转到您的虚拟环境“venv”/lip/python3.X/site-packages/leaflet/templates/leaflet/admin/widget.html 和所有的。 HTML files in the directory
目录中的HTML文件
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' %}">
My issue was in step 4 from documentation here: https://docs.djangoproject.com/en/3.2/howto/static-files/我的问题出在此处文档的第 4 步中: https ://docs.djangoproject.com/en/3.2/howto/static-files/
"4. Store your static files in a folder called static in your app. For example my_app/static/my_app/example.jpg." “4. 将静态文件存储在应用程序中名为 static 的文件夹中。例如 my_app/static/my_app/example.jpg。”
Once I had corrected my directory structure to match everything worked.一旦我纠正了我的目录结构以匹配所有工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.