Forums

'staticfiles' is not a valid tag library: Template library staticfiles not found

I am using virtualenv with Django 1.7 and Pythion 2.7

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()

I am getting error

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

Exception Location: /usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py in load, line 1054

Error at index.html

{% load staticfiles %}

Please help. Thanks in advance.

Can I take a look at your files? I will be able to see them from our side, but we always ask for permission first.

Sure giles. Please check the files.Thanks!

OK, I think I can see the problem. Your web app is configured by the WSGI application defined in /var/www/movies_pythonanywhere_com_wsgi.py (there's a link on the "Web" tab) but the WSGI file that you have made the (correct) changes to is inside your Django application's directory.

The best thing is probably to modify /var/www/movies_pythonanywhere_com_wsgi.py so that it imports the WSGI application from the one in the Django project, like this:

import os
import sys

# add your project directory to the sys.path
project_home = u'/home/movies/patherlist'
if project_home not in sys.path:
    sys.path.append(project_home)

from wsgi import application

Sorry Giles, it did not work,

i changed the complete code of '/var/www/movies_pythonanywhere_com_wsgi.py' to the following,

import os
import sys

# add your project directory to the sys.path
project_home = u'/home/movies/patherlist'
if project_home not in sys.path:
    sys.path.append(project_home)

from wsgi import application

returned error ImportError: No module named wsgi

Commenting "from wsgi import application" returns the follwoing error

AttributeError: 'module' object has no attribute 'application'

So I changed the wsgi to the following,

import os
import sys

project_home = u'/home/movies/patherlist'
if project_home

not in sys.path:
    sys.path.append(project_home)

os.environ['DJANGO_SETTINGS_MODULE'] = 'pantherlist.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

but it returned the same error

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

also even though I setup virtualenv with Django 1.7, the error log says 'Django Version: 1.3.7', I am not sure why.

Please help. Thanks..

Thanks Giles, I was able to fix it with your help. My /var/www/movies_pythonanywhere_com_wsgi.py' code is

activate_this = '/home/movies/.virtualenvs/django17/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

import os
import sys

path = '/home/movies/patherlist'
if path not in sys.path:
    sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'pantherlist.settings'

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

OK, glad you got it working! Perhaps the problem with my original suggestion was a clash between your wsgi.py and another module called WSGI elsewhere.