块标签无效:'static' [英] Invalid block tag: 'static'

查看:153
本文介绍了块标签无效:'static'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

服务器返回
/
中的TemplateSyntaxError无效的块标记:'static'

在此行上: < img src ={%static'icon / logo.png'%}>

whold html文件就像这是(另一个是html文件{%include%}):

The whold html file is like this (it's an html file {% include %}ed by another one):

{% load staticfiles %}
<div class="header">
    <nav>
      <ul class="nav nav-pills pull-right">
        <li role="presentation"><a href="{% url 'offer rank' %}">潮品榜</a></li>
        <li role="presentation"><a href="{% url 'user rank' %}">达人榜</a></li>
        <li role="presentation"><a href="#" data-toggle="modal" data-target="#start">登陆</a></li>
        <li role="presentation"><a href="#" data-toggle="modal" data-target="#start">注册</a></li>
        {% if debug_users %}
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">切换用户<span class="caret"></span></a>
          <ul class="dropdown-menu" role="menu">
            {% for debug_user in debug_users %}
            <li><a href="{% url 'debug login' debug_user.id %}">{% if debug_user.kbjuser.user_type == '1' %}达人{% else %}商家{% endif %}: {{ debug_user.username }}</a></li>
            {% endfor %}
          </ul>
        </li>
        {% endif %}
      </ul>
    </nav>
     <h3><img src="{% static 'icon/logo.png' %}">
        <a href="{% url 'home' %}" class="text-muted">口碑街</a>
    </h3>
</div>

并且settings.py是这样的:

And settings.py is like this:

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media/")


from hw.settings import *
from useraccess.settings import *

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    # other finders..
    'compressor.finders.CompressorFinder',
)

COMPRESS_ENABLED = True

我不知道这里发生了什么。

I can't figure out what happens here.

以下是settings.py中的更多行:

Here are some more lines in settings.py:

# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'mptt',
    'hw',
    'useraccess',
    'proxy',
    'compressor',
    'sekizai',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'useraccess.middleware.VisitCollectMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',

)

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.i18n',
    'django.core.context_processors.request',
    'django.core.context_processors.media',
    'django.core.context_processors.static',
    'hw.context_processors.user_info',
    'hw.context_processors.login_form',
    'hw.context_processors.get_all_user',
    'sekizai.context_processors.sekizai',
)

ROOT_URLCONF = 'ddw.urls'

WSGI_APPLICATION = 'ddw.wsgi.application'

LOGIN_URL = '/login/'

推荐答案


确保您的
INSTALLED_APPS中包含'django.contrib.staticfiles'。

Make sure that 'django.contrib.staticfiles' is included in your INSTALLED_APPS.

这是第一个 在此清单

this is number one in this checklist

这篇关于块标签无效:'static'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆