Unable to minify html files using django-pipeline
Asked Answered
B

2

7

In accordance with the django-pipeline docs, I've added 'pipeline.middleware.MinifyHTMLMiddleware', to my MIDDLEWARE_CLASSES to minify html files. But, when I check the htmls that have been rendered while running the server, they are not minified. Can some one please suggest if I am missing anything.

Below are my MIDDLEWARE_CLASSES. I even tried with GZipMiddleware class enabled, but it still does'nt work. I have also tried with both DEBUG = False & DEBUG = True in settings.py with no success.

MIDDLEWARE_CLASSES = (
    #'django.middleware.gzip.GZipMiddleware',                            
    'pipeline.middleware.MinifyHTMLMiddleware',                         

    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'Testapp.signin.views.SocialAuthExceptionMiddleware',               

)

EDIT: Added Installed Apps and Static files storage settings.

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    #'django.contrib.admin',
    'social.apps.django_app.default',
    # 'django.contrib.admindocs',
    'Testapp',
    'signin',

    'pipeline',
)

STATICFILES_STORAGE     = 'pipeline.storage.PipelineCachedStorage'
Blatherskite answered 21/3, 2014 at 3:21 Comment(4)
Have you added pipeline to INSTALLED_APPS and set STATICFILES_STORAGE?Glassine
Yes, I did. I've added these settings to my question.Blatherskite
Does putting pipeline.middleware.MinifyHTMLMiddleware to the end of the MIDDLEWARE_CLASSES help?Glassine
Tried that too, without success..Blatherskite
Z
1

To work pipeline MinifyHTMLMiddleware change DEBUG = False in settings.py

DEBUG = false

Or add in settings.py

PIPELINE_ENABLED = True
Zoom answered 3/3, 2015 at 16:55 Comment(0)
B
-1

i've had the same issue, but I've found the solution. You have to add this Middleware class first: 'htmlmin.middleware.MarkRequestMiddleware',

When you do that it adds to request an attribute request._hit_htmlmin = True which is checked then in MinifyHTMLMiddleware class. Now it's working great.

Bathulda answered 1/6, 2014 at 10:16 Comment(1)
this question is about django-pipeline not django-htmlminBoredom

© 2022 - 2024 — McMap. All rights reserved.