TemplateSyntaxError'staticfiles'不是有效的标签库' [英] TemplateSyntaxError 'staticfiles' is not a valid tag library'

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

问题描述

我有一个非常奇怪的问题,试图在我的应用程序中获取 staticfiles taglib。我基本上得到以下错误:

I'm having a really strange issue trying to get the staticfiles taglib working in my application. I'm essentially getting the following error:

'staticfiles' is not a valid tag library: Template library staticfiles not found, tried django.templatetags.staticfiles,django.contrib.admin.templatetags.staticfiles

这是我的模板,它是投掷这个错误:

Here's my template which is throwing this error:

{% load staticfiles %}
<html>
    <head>
        {% block stylesheets %}
        <link rel="stylesheet" href="{% static "styles/bootstrap-1.2.0.min.css" %}">
        {% endblock %}
        <title>{% block title %}Tzibor{% endblock %}</title>
    </head>
    <body>
        <h1>It Works!</h1>
        {% block scripts %}
        <script type="text/javascript" src="{% static "scripts/jquery-1.6.2.min.js" %}"></script>
        {% endblock %}
    </body>
</html>

这是我的 settings.py



Here's my settings.py:

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (

)

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', 
        'NAME': '/tmp/project.db',
        'USER': '',                    
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
    }
}

TIME_ZONE = 'UTC'
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

USE_I18N = True
USE_L10N = True
MEDIA_ROOT = '' # abs fs path to upload dir
MEDIA_URL = ''
STATIC_URL = '/static/'

ADMIN_MEDIA_PREFIX = '/media/'

SECRET_KEY = '4qo&twl!=ty!n%1@h2nidz^ie@$^uu@*pz)(ol%ise0&g6*@&_'

#TEMPLATE_CONTEXT_PROCESSORS = (
#   "django.contrib.auth.context_processors.auth",
#   "django.core.context_processors.debug",
#   "django.core.context_processors.i18n",
#   "django.core.context_processors.media",
#   "django.core.context_processors.static",
#   "django.contrib.messages.context_processors.messages",
#)

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
    'django.template.loaders.eggs.Loader',
)

TEMPLATE_DIRS = (

)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'project.urls'

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'django.contrib.admindocs',
    'django.contrib.staticfiles',
    'project.web',
    'south',
)

本质上,我遵循指南在Django关于如何设置静态服务应用程序的文档中,和得到这个错误。谁能看到问题是什么?我错过了什么吗?

Essentially, I followed the guide available in Django's documentation on how to set up the static serving application, and got this error. Can anyone see what the issue is? Am I missing something?

完整的堆栈跟踪 here

推荐答案

你可能正在运行django 1.3对!

You probably are running django 1.3 right!?

所以,请注意django dev(1.4)和django 1.3之间的区别:

So, notice the difference between django dev(1.4) and django 1.3:

  • 1.3 : https://docs.djangoproject.com/en/1.3/howto/static-files/#with-a-template-tag
  • dev : https://docs.djangoproject.com/en/dev/howto/static-files/#with-a-template-tag

所以如果你想使用{%load staticfiles%}你必须使用django dev(1.4 +)

So if you wanna use "{% load staticfiles %}" u must be using django dev(1.4+)

这是如何在django 1.3中使用的:

This is how to use in django 1.3 :

{% load static %}
<img src="{% get_static_prefix %}images/hi.jpg" />

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

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