在 Windows 下使用 Django_compressor ES6Compiler
Use Django_compressor ES6Compiler under Windows
我尝试 运行 我在 Linux 下开发的 Django 应用程序 Windows 设置。
应用程序启动,但是当我进入一个带有模板的页面时,该模板使用这样的压缩器("index.js" 导入 npm 包):
{% load static %}
{% load compress %}
<html>
...
<body>
...
{% compress js %}
<script type="module" src="{% static 'index.js' %}"></script>
{% endcompress %}
</body>
</html>
..我得到这个错误:
Traceback (most recent call last):
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\neuz8t\Downloads\cs_viewer_server\cs_viewer\views.py", line 19, in index
return render(request,'cs_viewer/index.html',{'graph_elements':tmp_graph_elements_json})
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\django\shortcuts.py", line 36, in render
content = loader.render_to_string(template_name, context, request, using=using)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\loader.py", line 62, in render_to_string
return template.render(context, request)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\backends\django.py", line 61, in render
return self.template.render(context)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py", line 171, in render
return self._render(context)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py", line 937, in render
bit = node.render_annotated(context)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py", line 904, in render_annotated
return self.render(context)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\compressor\templatetags\compress.py", line 131, in render
return self.render_compressed(context, self.kind, self.mode, forced=forced)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\compressor\templatetags\compress.py", line 107, in render_compressed
rendered_output = compressor.output(mode, forced=forced)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\compressor\js.py", line 50, in output
ret.append(subnode.output(*args, **kwargs))
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\compressor\js.py", line 52, in output
return super(JsCompressor, self).output(*args, **kwargs)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\compressor\base.py", line 295, in output
output = '\n'.join(self.filter_input(forced))
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\compressor\js.py", line 60, in filter_input
for hunk in self.hunks(forced):
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\compressor\base.py", line 205, in hunks
precompiled, value = self.precompile(value, **options)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\compressor\base.py", line 276, in precompile
return True, filter.input(**kwargs)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\compressor_toolkit\precompilers.py", line 53, in input
return super(BaseCompiler, self).input(**kwargs)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\compressor\filters\base.py", line 196, in input
raise FilterError(err)
compressor.exception.FilterError: 'export' is not recognized as an internal or external command
compressor.exception.FilterError: 'export' is not recognized as an
internal or external command
我的设置看起来像:
STATIC_URL = '/static/'
STATICFILES_DIRS = [ "cs_viewer/static", ]
STATIC_ROOT="cs_viewer/static"
INSTALLED_APPS += (
'compressor',
'compressor_toolkit',
)
STATICFILES_FINDERS = (
'compressor.finders.CompressorFinder',
)
COMPRESS_CSS_FILTERS = [
'compressor.filters.css_default.CssAbsoluteFilter',
'compressor.filters.cssmin.CSSMinFilter',
'compressor.filters.template.TemplateFilter'
]
COMPRESS_JS_FILTERS = [
'compressor.filters.jsmin.JSMinFilter',
]
COMPRESS_PRECOMPILERS = (
('module', 'compressor_toolkit.precompilers.ES6Compiler'),
('css', 'compressor_toolkit.precompilers.SCSSCompiler'),
)
COMPRESS_ENABLED = True
我尝试了不同的方法,包括重新安装所有依赖项、重新安装所有 npm 包……直到现在都没有任何效果。
您似乎在使用 ES6Compiler from compressor_toolkit。
那个 is using the export
command,仅在 Linux 上可用。您需要请求 compressor_toolkit 项目添加 windows 支持,或者自己构建并进行 PR,或者使用 linux :)
我尝试 运行 我在 Linux 下开发的 Django 应用程序 Windows 设置。 应用程序启动,但是当我进入一个带有模板的页面时,该模板使用这样的压缩器("index.js" 导入 npm 包):
{% load static %}
{% load compress %}
<html>
...
<body>
...
{% compress js %}
<script type="module" src="{% static 'index.js' %}"></script>
{% endcompress %}
</body>
</html>
..我得到这个错误:
Traceback (most recent call last):
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\neuz8t\Downloads\cs_viewer_server\cs_viewer\views.py", line 19, in index
return render(request,'cs_viewer/index.html',{'graph_elements':tmp_graph_elements_json})
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\django\shortcuts.py", line 36, in render
content = loader.render_to_string(template_name, context, request, using=using)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\loader.py", line 62, in render_to_string
return template.render(context, request)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\backends\django.py", line 61, in render
return self.template.render(context)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py", line 171, in render
return self._render(context)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py", line 937, in render
bit = node.render_annotated(context)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py", line 904, in render_annotated
return self.render(context)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\compressor\templatetags\compress.py", line 131, in render
return self.render_compressed(context, self.kind, self.mode, forced=forced)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\compressor\templatetags\compress.py", line 107, in render_compressed
rendered_output = compressor.output(mode, forced=forced)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\compressor\js.py", line 50, in output
ret.append(subnode.output(*args, **kwargs))
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\compressor\js.py", line 52, in output
return super(JsCompressor, self).output(*args, **kwargs)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\compressor\base.py", line 295, in output
output = '\n'.join(self.filter_input(forced))
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\compressor\js.py", line 60, in filter_input
for hunk in self.hunks(forced):
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\compressor\base.py", line 205, in hunks
precompiled, value = self.precompile(value, **options)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\compressor\base.py", line 276, in precompile
return True, filter.input(**kwargs)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\compressor_toolkit\precompilers.py", line 53, in input
return super(BaseCompiler, self).input(**kwargs)
File "C:\Users\neuz8t\AppData\Local\Programs\Python\Python37\lib\site-packages\compressor\filters\base.py", line 196, in input
raise FilterError(err)
compressor.exception.FilterError: 'export' is not recognized as an internal or external command
compressor.exception.FilterError: 'export' is not recognized as an internal or external command
我的设置看起来像:
STATIC_URL = '/static/'
STATICFILES_DIRS = [ "cs_viewer/static", ]
STATIC_ROOT="cs_viewer/static"
INSTALLED_APPS += (
'compressor',
'compressor_toolkit',
)
STATICFILES_FINDERS = (
'compressor.finders.CompressorFinder',
)
COMPRESS_CSS_FILTERS = [
'compressor.filters.css_default.CssAbsoluteFilter',
'compressor.filters.cssmin.CSSMinFilter',
'compressor.filters.template.TemplateFilter'
]
COMPRESS_JS_FILTERS = [
'compressor.filters.jsmin.JSMinFilter',
]
COMPRESS_PRECOMPILERS = (
('module', 'compressor_toolkit.precompilers.ES6Compiler'),
('css', 'compressor_toolkit.precompilers.SCSSCompiler'),
)
COMPRESS_ENABLED = True
我尝试了不同的方法,包括重新安装所有依赖项、重新安装所有 npm 包……直到现在都没有任何效果。
您似乎在使用 ES6Compiler from compressor_toolkit。
那个 is using the export
command,仅在 Linux 上可用。您需要请求 compressor_toolkit 项目添加 windows 支持,或者自己构建并进行 PR,或者使用 linux :)