Pythonanywhere的'staticfiles'不是一个有效的标签库:找不到模板库staticfiles。

3
在PythonAnywhere中,我正在使用Django 1.7和Python 2.7的virtualenv。 Settings.py
STATIC_ROOT = '/home/movies/pantherlist/movies/static/'
STATIC_URL = '/static/'

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'pantherlist.movies',
)

wsgi.py

activate_this = '/home/movies/.virtualenvs/django17/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
.
.#path setup already done here
.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

我遇到了错误

异常类型: 模板语法错误 异常信息:
'staticfiles' 不是一个有效的标签库:模板库 staticfiles 未找到,尝试过 django.templatetags.staticfiles,django.contrib.admin.templatetags.staticfiles

异常位置: /usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py in load, 第1054行

错误发生在index.html

{% load staticfiles %}

请帮忙。先行致谢。

2个回答

4

看起来你还没有重新加载Web应用程序,从而添加虚拟环境激活到你的wsgi文件,或者你没有使用你认为你正在使用的wsgi文件。Django报告的错误位置(/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py)在PythonAnywhere上默认的系统Django中,而不是你虚拟环境中的Django。


你是对的。我已经修复了那个问题。我在我的项目文件夹中创建了一个wsgi文件并正在更改它,这是一个错误。我应该直接在“web”选项卡中更改PythonAnywhere wsgi文件。 - Vyas Rao

0

尝试:

{% load static from staticfiles %}

现在你可以这样使用它:

{% static "images/hi.jpg" as myphoto %}
<img src="{{ myphoto }}" alt="Hi!" />

这个例子来自Django 1.7版本的文档。


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