I have the code below to load static files, but I keep getting a TemplateSyntaxError
. Does anyone know how I can fix this issue?
Template:
{% load staticfiles %}
{% load static %}
<img class="logo" alt="Test Pic" src="{% static 'images/logo.png' %}" width="110" height="70">
{% block main %}
{% endblock %}
Settings:
INSTALLED_APPS = [
...,
'django.contrib.staticfiles',
]
STATIC_URL = '/public/'
STATIC_ROOT = os.path.join(BASE_DIR, "public")
URLS:
urlpatterns = [
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Error I get:
Invalid block tag on ...: 'static', expected 'endblock'. Did you forget to register or load this tag?
Just use {% load static %} on the top since it is recommended in newer versions of Django. I think using staticfiles and static at the same time creates a confusion.
解决此问题的是重新安装Django。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.