20

我正在尝试来自http://django-oscar.readthedocs.org/en/latest/internals/getting_started.html的 django-oscar 教程,但我得到了一个

'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

有任何想法吗??

追溯:

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
4

2 回答 2

51

如果您正在运行 Django 3 并且之前使用的是旧版本,则需要替换:

{% load static from staticfiles %}或者{% load staticfiles %}

只需:

{% load static %}

资源

于 2019-12-17T19:59:39.203 回答
21

您需要添加

django.contrib.staticfiles

INSTALLED_APPS

配置静态文件的文档

于 2013-08-19T19:38:54.190 回答