The Python Oracle

Django TemplateSyntaxError - 'staticfiles' is not a registered tag library

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Magical Minnie Puzzles

--

Chapters
00:00 Django Templatesyntaxerror - 'Staticfiles' Is Not A Registered Tag Library
00:23 Accepted Answer Score 381
00:45 Answer 2 Score 2
01:03 Answer 3 Score 20
01:24 Answer 4 Score 9
01:35 Thank you

--

Full question
https://stackoverflow.com/questions/5592...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #django #djangotemplates #django30

#avk47



ACCEPTED ANSWER

Score 381


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.




ANSWER 2

Score 20


  • Try {% load static %} instead of {% 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
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')



ANSWER 3

Score 9


This worked for me using django 3.1.4.

{% load static %}
<link rel="stylesheet" href="{% static 'style.css' %}">

its working for me




ANSWER 4

Score 2


this worked with me replace {% load static from staticfiles %} with {% load static %}

where :

go to your virtual environment "venv" /lip/python3.X/site-packages/leaflet/templates/leaflet/admin/widget.html and all of the .HTML files in the directory