[Fixed]-No module named 'django.contrib.staticfiles.templatetags'

9👍

django.contrib.staticfiles.templatetags was removed in version 3

The staticfiles and admin_static template tag libraries are removed.

The django-summernote package has not been updated since January and does not support Django 3

39👍

I’ll leave this here just in case other people end up in this question to fix django 3 function location change.

It seems like in django 3, static templatetag is moved among builtin template tags.

https://docs.djangoproject.com/en/3.0/ref/templates/builtins/#std:templatetag-static

https://github.com/django/django/blob/50cf183d219face91822c75fa0a15fe2fe3cb32d/django/templatetags/static.py#L162

So instead of importing it from here: from django.contrib.staticfiles.templatetags.staticfiles import static, you need to import it from here: from django.templatetags.static import static

12👍

This is going to be pretty common for a while as everyone starts to move into Django 3 over the next few years.

In addition to the accepted answer, this is what I’ve been adding to support both Django 2 and Django 3 static imports (esp. helpful with managing packages)

try:
    # Django 2
    from django.contrib.staticfiles.templatetags.staticfiles import static
except ModuleNotFoundError:
    # Django 3
    from django.templatetags.static import static

0👍

check the commas in the list of installed apps
one comma can ruin your life

Leave a comment