简体   繁体   English

Django加载静态文件时出现错误?

[英]Django geting error when loading static files?

I have the code below to load static files, but I keep getting a TemplateSyntaxError . 我有下面的代码来加载静态文件,但我不断收到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. 仅在顶部使用{%load static%},因为在较新版本的Django中建议使用。 I think using staticfiles and static at the same time creates a confusion. 我认为同时使用staticfiles和static会造成混乱。

解决此问题的是重新安装Django。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM