zoukankan      html  css  js  c++  java
  • Invalid block tag--static

    很久没有动手写写项目了,这几天抽空打算用Django 3.0写点东西。在一个页面引入图片,代码如下:
    src="{% static 'index/logo.png' %}"

    遇到了如下报错,反复查看了代码,都没有什么缺失或者不完整。

    django.template.exceptions.TemplateSyntaxError: Invalid block tag on line 9: 'static', expected 'endblo

    接下来主要进行排错:

    static配置是否正确,(正确)

    图片路径是否正确,(正确)

    块标记是否完整, (完整)

    最后通过相关查询,当前页面的继承块(block)中,使用了static,因此需要在当前html页面中再次加入了如下代码解决报错。

    {% load static %}

     记得之前的django'版本中并没有出现这样的问题。并且在模板继承中,基模板中我也使用了{% load static %},有些不解?

    通过进一步的查询,修改setting文件可省略在页面中引入{% load static %},setting中具体修改为:

    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [os.path.join(BASE_DIR,'apps/login/templates')],

            'APP_DIRS': True,
            'OPTIONS': {
                'context_processors': [
                    'django.template.context_processors.debug',
                    'django.template.context_processors.request',
                    'django.contrib.auth.context_processors.auth',
                    'django.contrib.messages.context_processors.messages',
                ],

            'builtins':
                    ['django.templatetags.static']   #新增,在模板中可省略 {% load static %}
            },

        },
    ]
  • 相关阅读:
    Install Failed Insufficient Storage, 解决 ADB 安装APK失败问题
    finding-the-smallest-circle-that-encompasses-other-circles
    PyTorch for Semantic Segmentation
    Semantic-Segmentation-DL
    Awesome Semantic Segmentation
    应用于语义分割问题的深度学习技术综述
    JS打开浏览器
    Overcoming iOS HTML5 audio limitations
    Android APP Testing Tutorial with Automation Framework
    基于方向包围盒投影转换的轮廓线拼接算法
  • 原文地址:https://www.cnblogs.com/reaptem/p/12684077.html
Copyright © 2011-2022 走看看