简体   繁体   English

Django TemplateSyntaxError - 'staticfiles' 不是注册的标签库

[英]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 中删除

  • Try {% load static %} instead of {% load staticfiles %}尝试{% load static %}而不是{% load staticfiles %}
  • If effect of CSS or any other files doesn't reflect in your template then also write following lines in the end of your settings.py file如果 CSS 或任何其他文件的效果没有反映在您的模板中,那么还要在您的settings.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.

相关问题 /&#39;staticfiles&#39; 处的 Django TemplateSyntaxError 不是已注册的标记库。 必须是以下之一:admin_list admin_modify admin_urls - Django TemplateSyntaxError at / 'staticfiles' is not a registered tag library. Must be one of: admin_list admin_modify admin_urls /en/admin/login/ 'staticfiles' 处的 TemplateSyntaxError 不是已注册的标签库。 必须是以下之一: - TemplateSyntaxError at /en/admin/login/ 'staticfiles' is not a registered tag library. Must be one of: TemplateSyntaxError &#39;apptags&#39; 不是注册的标签库 - TemplateSyntaxError 'apptags' is not a registered tag library Django 3 TemplateSyntaxError: 'css/bootstrap.min.css' 不是注册的标签库 - Django 3 TemplateSyntaxError: 'css/bootstrap.min.css' is not a registered tag library 静态文件不是注册标签,静态文件未加载 - Staticfiles not a registered tag and staticfiles not loading django.template.exceptions.TemplateSyntaxError:&#39;static&#39;不是已注册的标记库。 必须是以下之一: - django.template.exceptions.TemplateSyntaxError: 'static' is not a registered tag library. Must be one of: django_rest_swagger - &#39;staticfiles&#39; 不是注册的标签库。 必须是以下之一: - django_rest_swagger - 'staticfiles' is not a registered tag library. Must be one of: “TemplateSyntaxError:&#39;humanize&#39;不是一个有效的标签库:”在DJango中 - “TemplateSyntaxError: 'humanize' is not a valid tag library:” in DJango /'xxx' 处的 TemplateSyntaxError 不是已注册的标签库。 必须是以下之一: - TemplateSyntaxError at / 'xxx' is not a registered tag library. Must be one of: &#39;staticfiles&#39; 不是注册标签库:这些解决方案不起作用 - 'staticfiles' is not a registered tag library: These solutions don't work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM