Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django压缩机在生产中不工作_Python_Django_Django Compressor - Fatal编程技术网

Python Django压缩机在生产中不工作

Python Django压缩机在生产中不工作,python,django,django-compressor,Python,Django,Django Compressor,我想使用django_压缩机,但它在我的生产环境中不起作用 在开发中(DEBUG=True),它正在工作并创建.sass缓存&缓存文件夹 我的设置.py是 DEBUG = False TEMPLATE_DEBUG = False INSTALLED_APPS = ( ..., 'django.contrib.staticfiles', 'compressor', 'myapp', ) STATIC_URL = '/static/' STATIC_ROOT = os

我想使用django_压缩机,但它在我的生产环境中不起作用

在开发中(
DEBUG=True
),它正在工作并创建
.sass缓存
&
缓存
文件夹

我的
设置.py

DEBUG = False
TEMPLATE_DEBUG = False
INSTALLED_APPS = (
    ...,
    'django.contrib.staticfiles',
    'compressor',
    'myapp',
)
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'com.app.static')↲
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'compressor.finders.CompressorFinder',
)
COMPRESS_ENABLED = True
COMPRESS_ROOT = STATIC_ROOT
COMPRESS_PRECOMPILERS = (
    ('text/x-scss', 'sass --scss {infile} {outfile}'),
)
MEDIA_URL = '/media/'
scss文件将模板目录放在应用程序上

{% load staticfiles %}
{% load compress %}
<html>
<head>
    {% compress css %}
        <link rel='stylesheet' type='text/scss' href="{% static 'top/css/top.scss' %}" charset='utf-8'>
    {% endcompress %}
</head>
</html>
{%load staticfiles%}
{%load compress%}
{%css%}
{%endcompress%}

快速查看文档可以找到答案:

django.conf.settings.COMPRESS_ENABLED应设置为True,否则与调试相反

更新


抱歉,这太尴尬了,我完全错过了设置中的:COMPRESS\u ENABLED=True

将此添加到
settings.py

COMPRESS_OFFLINE = True
压缩

python manage.py compress

我试过这个。“已启用压缩=未调试”。仍然不起作用。你可以检查静态日志,看看压缩是否真的发生了。python manage.py是静态的。并且,1个静态文件复制到“/opt/webapps/src/com.app.static”。但我不知道compressed.copied文件是否被压缩。只是css文件。嗨,我试过“python manage.py compress”。在那之后,那就行了!谢谢。没有离线压缩,你怎么做?如果COMPRESS\u OFFLINE=True且COMPRESS\u ENABLED=True,则不适用于我。。我必须运行离线压缩。我必须添加COMPRESS\u OFFLINE\u上下文,以便正确运行动态上下文。