Comments (3)
In Django 2.1 we need to decode response.content
first before passing to htmlmin
Here is my HTMLMinMiddleware
class HTMLMinMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
response = self.get_response(request)
if 'text/html' in response.get('Content-Type', ''):
try:
match = re.search(r'charset=([^;\s]+)', response['Content-Type'])
encoding = match.group(1) if match else 'utf-8'
response.content = htmlmin.minify(response.content.decode(encoding),
remove_comments=True,
remove_empty_space=True,
pre_tags=(u'pre', u'code', u'textarea'))
except Exception as e:
logger(e)
return response
from django-htmlmin.
HTML minify is not working with Django 2.1 and python 3.6
Causing below error in nginx:
[error] 21883#21883: *22 upstream prematurely closed connection while reading upstream,
Without any error in gunicorn or django log files
I'm using 'htmlmin.middleware.HtmlMinifyMiddleware',
from django-htmlmin.
The support for 2.1 was released in the htmlmin 0.11 version
from django-htmlmin.
Related Issues (20)
- It strips the <head></head> content
- Strange issue with content length when using django cache HOT 1
- ImportError: Module "htmlmin.middleware" does not define a "HtmlMinifyMiddleware" attribute/class HOT 1
- Code is rendered outside header tags HOT 3
- Favicon not showing
- Minify closes <form> tag erroneously HOT 1
- Will this app evolve? HOT 4
- HTML MINIFY not Working! HOT 4
- Can I avoid the automatic addition of <html> <head> <body> tags ? HOT 1
- Unexpected html HOT 1
- Only script tag are appearing on head tag?
- Is it possible to exclude the inner HTML of a class from being minified?
- Django cache per view
- problem using html_minify in django
- travis-ci.org shutdown HOT 2
- need to retain space around inline, inline-block, and comment
- Lighthouse returned error: NOT_HTML, the page served as text/plain instead of text/html HOT 1
- No wheel available for 0.11.0 on PyPI
- Trailing slash on void elements
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-htmlmin.