I have the following code block where a corresponding .css
file's path is returned.
It is part of a Theme-Class
that allows the user to change the website theme (dark and light)
from a button in the profile view.
def link(self) -> str:
"""
Returns the link where the CSS file for this theme is located
"""
return static('app_shared/colors_%s.css' % self.name())
The same problem when it occurs in an HTML-Template can be solved by changing {% load staticfiles %}
to {% load static %}
. Obviously for source code I will need another alternative.
django.contrib.staticfiles.templatetags was deprecated in Django's version 2.1. And now it has been completely removed from version 3.
Simply, replace
from django.contrib.staticfiles.templatetags.staticfiles import static
with
from django.templatetags.static import static
Hope this will help...
You're misunderstanding what's being removed. django.contrib.staticfiles.templatetags.static()
is deprecated in favor of django.templatetags.static.static()
. If you use the latter, everything will work as you expect it.
See the Django 2.1 release notes, when this was deprecated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With