模板语法错误 'staticfiles' 不是有效的标签库。

10

我在尝试让staticfiles标签库在我的应用程序中工作时遇到了一个非常奇怪的问题。我基本上得到了以下错误:

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

这是我的模板,出现了以下错误:

{% 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文件:

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文档中有关如何设置静态文件服务应用程序的指南 进行操作,但是出现了此错误。有人能看出问题所在吗?我漏掉了什么吗?

完整的堆栈跟踪在此处


@Jordan Reiter,ImportError: No module named staticfiles - Naftuli Kay
@Skirmantas,遇到了这个问题,已经修复了,但仍然出现错误。 - Naftuli Kay
python manage.py shell 中尝试使用 import django.contrib.staticfiles.templatetags.staticfiles - Ski
在“django.contrib.staticfiles”中没有名为“templatetags.staticfiles”的包。我正在使用Buildout运行,所以除了Django本身之外,是否还需要包括其他软件包?我正在运行Django 1.3。 - Naftuli Kay
1
据我所知,这是在开发版本中新增的,而不是1.3版本。请查看文档中的静态标签,并将其与1.3版本进行比较。 - mkriheli
显示剩余6条评论
1个回答

33

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接