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 565965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:55:40+00:00 2026-05-13T12:55:40+00:00

I am using Jinja2 to generate HTML files which are typically very huge in

  • 0

I am using Jinja2 to generate HTML files which are typically very huge in size. I noticed that the generated HTML had a lot of whitespace. Is there a pure-Python tool that I can use to minimize this HTML? When I say “minimize”, I mean remove unnecessary whitespace from the HTML (much like Google does — look at the source for google.com, for instance)

I don’t want to rely on libraries/external-executables such as tidy for this.

For further clarification, there is virtually no JavaScript code. Only HTML content.

  • 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-05-13T12:55:41+00:00Added an answer on May 13, 2026 at 12:55 pm

    If you just want to get rid of excess whitespace, you can use:

    >>> import re
    >>> html_string = re.sub(r'\s\s+', ' ', html_string)
    

    or:

    >>> html_string = ' '.join(html_string.split())
    

    If you want to do something more complicated than just stripping excess whitespace, you’ll need to use more powerful tools (or more complex regexps).

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

Sidebar

Related Questions

I'm using flask with a jinja2 template which includes another jinja2 template called buttons.html.
I just recently started using Jinja2 for HTML templating on Google App Engine and
So, I have a django project that is using jinja2 rendering, and I also
I'm using Jinja2's nl2br filter, which looks like: import re from jinja2 import environmentfilter,
I'm using Jinja2 on Google App Engine. I have a ListView which renders a
I'm running the micro framework Bottle on Google App Engine. I'm using Jinja2 for
Using Nunit, I want to be able to write a test fixture that will
Using top it's easy to identify processes that are hogging memory and cpu, but
I'm very new to jinja2 and the use of templates in general so I
When creating templates I typically have 3 separate parts (header, body, footer) which I

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.