1

所以网站本身运行没有任何我能找到的错误。

我已经安装了收缩,我正在尝试运行收集静态。在运行过程中,它给了我一个 TemplateSyntaxError。回溯中的每个文件都是一个站点包文件,我不确定如何查找错误的来源。是否有任何工具可以检查并让我看到它在哪里/如何处理,这样我也许可以找到错误的来源?

这是我的回溯:

> You have requested to collect static files at the destination location
> as specified in your settings.
> 
> This will overwrite existing files! Are you sure you want to do this?
> 
> Type 'yes' to continue, or 'no' to cancel: yes
> 
> 0 static files copied, 1249 unmodified. Traceback (most recent call
> last):   File "tools/manage.py", line 16, in <module>
>     execute_manager(settings)   File "/home/adam/pyprojects/trekadoo-web/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py",
> line 459, in execute_manager
>     utility.execute()   File "/home/adam/pyprojects/trekadoo-web/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py",
> line 382, in execute
>     self.fetch_command(subcommand).run_from_argv(self.argv)   File "/home/adam/pyprojects/trekadoo-web/venv/local/lib/python2.7/site-packages/django/core/management/base.py",
> line 196, in run_from_argv
>     self.execute(*args, **options.__dict__)   File "/home/adam/pyprojects/trekadoo-web/venv/local/lib/python2.7/site-packages/django/core/management/base.py",
> line 232, in execute
>     output = self.handle(*args, **options)   File "/home/adam/pyprojects/trekadoo-web/venv/local/lib/python2.7/site-packages/django/core/management/base.py",
> line 371, in handle
>     return self.handle_noargs(**options)   File "/home/adam/pyprojects/trekadoo-web/venv/local/lib/python2.7/site-packages/shrink/management/commands/collectstatic.py",
> line 58, in handle_noargs
>     templates.add(get_template(pjoin(dirpath, f)))   File "/home/adam/pyprojects/trekadoo-web/venv/local/lib/python2.7/site-packages/django/template/loader.py",
> line 145, in get_template
>     template, origin = find_template(template_name)   File "/home/adam/pyprojects/trekadoo-web/venv/local/lib/python2.7/site-packages/django/template/loader.py",
> line 134, in find_template
>     source, display_name = loader(name, dirs)   File "/home/adam/pyprojects/trekadoo-web/venv/local/lib/python2.7/site-packages/django/template/loader.py",
> line 42, in __call__
>     return self.load_template(template_name, template_dirs)   File "/home/adam/pyprojects/trekadoo-web/venv/local/lib/python2.7/site-packages/django/template/loader.py",
> line 48, in load_template
>     template = get_template_from_string(source, origin, template_name)   File
> "/home/adam/pyprojects/trekadoo-web/venv/local/lib/python2.7/site-packages/django/template/loader.py",
> line 156, in get_template_from_string
>     return Template(source, origin, name)   File "/home/adam/pyprojects/trekadoo-web/venv/local/lib/python2.7/site-packages/django/template/base.py",
> line 125, in __init__
>     self.nodelist = compile_string(template_string, origin)   File "/home/adam/pyprojects/trekadoo-web/venv/local/lib/python2.7/site-packages/django/template/base.py",
> line 153, in compile_string
>     return parser.parse()   File "/home/adam/pyprojects/trekadoo-web/venv/local/lib/python2.7/site-packages/django/template/base.py",
> line 267, in parse
>     compiled_result = compile_func(self, token)   File "/home/adam/pyprojects/trekadoo-web/venv/local/lib/python2.7/site-packages/django/template/loader_tags.py",
> line 214, in do_extends
>     nodelist = parser.parse()   File "/home/adam/pyprojects/trekadoo-web/venv/local/lib/python2.7/site-packages/django/template/base.py",
> line 267, in parse
>     compiled_result = compile_func(self, token)   File "/home/adam/pyprojects/trekadoo-web/venv/local/lib/python2.7/site-packages/django/template/loader_tags.py",
> line 189, in do_block
>     nodelist = parser.parse(('endblock',))   File "/home/adam/pyprojects/trekadoo-web/venv/local/lib/python2.7/site-packages/django/template/base.py",
> line 246, in parse
>     filter_expression = self.compile_filter(token.contents)   File "/home/adam/pyprojects/trekadoo-web/venv/local/lib/python2.7/site-packages/django/template/base.py",
> line 346, in compile_filter
>     return FilterExpression(token, self)   File "/home/adam/pyprojects/trekadoo-web/venv/local/lib/python2.7/site-packages/django/template/base.py",
> line 557, in __init__
>     filter_func = parser.find_filter(filter_name)   File "/home/adam/pyprojects/trekadoo-web/venv/local/lib/python2.7/site-packages/django/template/base.py",
> line 352, in find_filter
>     raise TemplateSyntaxError("Invalid filter: '%s'" % filter_name) django.template.base.TemplateSyntaxError: Invalid filter: 'add_class'

add_class 在整个项目中使用了数百次。

4

1 回答 1

2

好的,所以在 PyCharm 中,我在调试模式下将“manage.py collectstatic”作为 python 脚本运行,并在回溯中提到的 django 核心文件中放置断点。

然后,我能够回到框架中,直到找到它所引用的文件。为什么该文件不会在回溯中列出,这超出了我的理解。但是那个文件缺少一个

{% load widget_tweaks %}

添加并修复。

于 2015-03-24T18:00:16.460 回答