Skip to content

Disable HtmlPrettifyMiddleware by default in development mode

HtmlPrettifyMiddleware uses the prettify() method from BeautifulSoup. Its documentation says:

Since it adds whitespace (in the form of newlines), prettify() changes the meaning of an HTML document and should not be used to reformat one. The goal of prettify() is to help you visually understand the structure of the documents you work with.

Having HtmlPrettifyMiddleware enabled by default in development mode therefore leads to surprising behavior, like extra spaces surrounding “something” when writing <code>something</code> in a template.

While it can be useful in some cases, it is better disabled by default to have matching behaviors between development and production modes.

Merge request reports