Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8299049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:00:40+00:00 2026-06-08T16:00:40+00:00

I am using django templating, and for readability I have html that looks similar

  • 0

I am using django templating, and for readability I have html that looks similar to the following:

{% if some_variable %}
    text
{% else %}
    nothing exists here
{% endif %}

{% for item in set %}
    {% if forloop.first %}
...etc...

It converts to the following html at runtime, which includes tons of whitespace and returns:

text

<div>

  <li

        class='some_class

    >

    some text

   </li>

</div>

etc...

Some pages even run to ~3,000 lines of html when viewing the page source.

Is there a tool to compress this html at runtime? What about a tool to remove extra line breaks?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T16:00:42+00:00Added an answer on June 8, 2026 at 4:00 pm

    For a bit of background, this is done intentionally, since Django’s templating engine currently doesn’t care about sanitizing lines that evaluate to blanks after the tags get stripped out and doing so will incur some minor performance penalties in serving the response, since it involves a post-processing step that evaluates the full contents of the rendered template.

    Still, if you need a quick solution, I suggest you employ the StripWhitespaceMiddleware response middleware that’ll remove spurious whitespaces from textual responses. It’s pretty fast and straightforward, employing regular expression matching like the templating engine itself. A more taxing, but powerful alternative would be deploy a response middleware that utilizes an HTML prettifier, if you really care about the poor human beings still reading raw responses.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using django 1.4 and have seen that when you use startproject it now creates
So, I have a django project that is using jinja2 rendering, and I also
Using the standard Django templating system, is there any snippet/reusable template tag to have
I'm using Django templating with Google App Engine. I'm trying unsuccessfully to print out
using django 1.4 I have a model with a datetimefield. I imported django.utils.timezone to
I using Django tagging project. That is was very stable project. Working on django
I am using django-registration and would like to have a different page for failed
I'm building an application, that uses the Django templating engine / language to compile
I using Django and a generic view django.views.generic.create_update.create_object I have a model form wich
When researching Google App Engine (GAE), it's clear that using Django is wildly popular

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.