问题
hey guys i am trying django-oscar tutorial from http://django-oscar.readthedocs.org/en/latest/internals/getting_started.html but i am getting a
'staticfiles' is not a valid tag library: Template library staticfiles not found, tried django.templatetags.staticfiles,django.contrib.flatpages.templatetags.staticfiles,compressor.templatetags.staticfiles,oscar.templatetags.staticfiles,haystack.templatetags.staticfiles,treebeard.templatetags.staticfiles,sorl.thumbnail.templatetags.staticfiles
any ideas??
traceback:
Environment:
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 1.4.2
Python Version: 2.7.3
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.flatpages',
'south',
'compressor',
'oscar',
'oscar.apps.analytics',
'oscar.apps.order',
'oscar.apps.checkout',
'oscar.apps.shipping',
'oscar.apps.catalogue',
'oscar.apps.catalogue.reviews',
'oscar.apps.basket',
'oscar.apps.payment',
'oscar.apps.offer',
'oscar.apps.address',
'oscar.apps.partner',
'oscar.apps.customer',
'oscar.apps.promotions',
'oscar.apps.search',
'oscar.apps.voucher',
'oscar.apps.dashboard',
'oscar.apps.dashboard.reports',
'oscar.apps.dashboard.users',
'oscar.apps.dashboard.orders',
'oscar.apps.dashboard.promotions',
'oscar.apps.dashboard.catalogue',
'oscar.apps.dashboard.offers',
'oscar.apps.dashboard.ranges',
'oscar.apps.dashboard.vouchers',
'oscar.apps.dashboard.communications',
'haystack',
'treebeard',
'sorl.thumbnail']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware')
Template error:
In template /home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/oscar/templates/oscar/partials/extrascripts.html, error at line 6
'staticfiles' is not a valid tag library: Template library staticfiles not found, tried django.templatetags.staticfiles,django.contrib.flatpages.templatetags.staticfiles,compressor.templatetags.staticfiles,oscar.templatetags.staticfiles,haystack.templatetags.staticfiles,treebeard.templatetags.staticfiles,sorl.thumbnail.templatetags.staticfiles
1 : {% comment %}
2 : Elastislide is used in several places where there are carousels, such as list
3 : content blocks and product images. As the content blocks could be on any page,
4 : we need to load the script everywhere - hence why it is here.
5 : {% endcomment %}
6 : {% load staticfiles %}
7 : {% load compress %}
8 :
9 : {% compress js %}
10 : <script src="{% static "oscar/js/elastislide/jquery.elastislide.js" %}" type="text/javascript" charset="utf-8"></script>
11 : {% endcompress %}
12 :
Traceback:
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
136. response = response.render()
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/response.py" in render
104. self._set_content(self.rendered_content)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/response.py" in rendered_content
81. content = template.render(context)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/base.py" in render
140. return self._render(context)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/base.py" in _render
134. return self.nodelist.render(context)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/base.py" in render
823. bit = self.render_node(node, context)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
74. return node.render(context)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
123. return compiled_parent._render(context)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/base.py" in _render
134. return self.nodelist.render(context)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/base.py" in render
823. bit = self.render_node(node, context)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
74. return node.render(context)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
101. compiled_parent = self.get_parent(context)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/loader_tags.py" in get_parent
98. return get_template(parent)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/loader.py" in get_template
145. template, origin = find_template(template_name)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/loader.py" in find_template
134. source, display_name = loader(name, dirs)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/loader.py" in __call__
42. return self.load_template(template_name, template_dirs)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/loader.py" in load_template
48. template = get_template_from_string(source, origin, template_name)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/loader.py" in get_template_from_string
156. return Template(source, origin, name)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/base.py" in __init__
125. self.nodelist = compile_string(template_string, origin)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/base.py" in compile_string
153. return parser.parse()
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/base.py" in parse
267. compiled_result = compile_func(self, token)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/loader_tags.py" in do_extends
214. nodelist = parser.parse()
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/base.py" in parse
267. compiled_result = compile_func(self, token)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/loader_tags.py" in do_block
189. nodelist = parser.parse(('endblock',))
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/base.py" in parse
267. compiled_result = compile_func(self, token)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/loader_tags.py" in do_include
262. isolated_context=isolated_context)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/loader_tags.py" in __init__
145. t = get_template(template_path)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/loader.py" in get_template
145. template, origin = find_template(template_name)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/loader.py" in find_template
134. source, display_name = loader(name, dirs)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/loader.py" in __call__
42. return self.load_template(template_name, template_dirs)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/loader.py" in load_template
48. template = get_template_from_string(source, origin, template_name)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/loader.py" in get_template_from_string
156. return Template(source, origin, name)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/base.py" in __init__
125. self.nodelist = compile_string(template_string, origin)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/base.py" in compile_string
153. return parser.parse()
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/base.py" in parse
267. compiled_result = compile_func(self, token)
File "/home/psychok7/code/comprasonline/venv/local/lib/python2.7/site-packages/django/template/defaulttags.py" in load
1043. (taglib, e))
Exception Type: TemplateSyntaxError at /
Exception Value: 'staticfiles' is not a valid tag library: Template library staticfiles not found, tried django.templatetags.staticfiles,django.contrib.flatpages.templatetags.staticfiles,compressor.templatetags.staticfiles,oscar.templatetags.staticfiles,haystack.templatetags.staticfiles,treebeard.templatetags.staticfiles,sorl.thumbnail.templatetags.staticfiles
回答1:
You need to add
django.contrib.staticfiles
to INSTALLED_APPS
Documentation on configuring Static files
回答2:
If you're running Django 3 and were on an older version before, you need to replace:
{% load static from staticfiles %}
or {% load staticfiles %}
with just:
{% load static %}
Source
回答3:
for Django 3.x use have to use {% load static %} tag instead of {% load staticfiles %}.
来源:https://stackoverflow.com/questions/18321684/staticfiles-is-not-a-valid-tag-library-template-library-staticfiles-not-found