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 %}
            },

        },
    ]
  • 相关阅读:
    多模块应用自动化部署
    shell杀死指定端口的进程
    SpringBoot打包成war
    Spring Boot:The field file exceeds its maximum permitted size of 1048576 bytes
    nginx上配置phpmyadmin
    Ubuntu16.04中php如何切换版本
    E:dpkg was interrupted, you must manually run'dpkg配置'to correct the problem.
    Edusoho之LAMP环境搭建
    cocos2d-x -3.81+win7+vs2013开发环境创建新的项目
    M2Mqtt is a MQTT client available for all .Net platform
  • 原文地址:https://www.cnblogs.com/reaptem/p/12684077.html
Copyright © 2011-2022 走看看