Open In App

Minify HTML in Flask using Flask-Minify

Last Updated : 04 Jul, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Flask offers HTML rendering as output, it is usually desired that the output HTML should be concise and it serves the purpose as well. In this article, we would display minification of output routes of Flask responses using the library – Flask-Minify.

Advantages of Minification

  • Websites load faster as fewer lines are there to upload and download.
  • Bandwidth cost is reduced as less data is flown over the network.
  • Decompression is not needed before usage.
  • As the site loads faster, UX and SEO improve as well.

Installation 

To install this module type the below command in the terminal.

pip install Flask-Minify

Function Used: minify(self, app=None, html=True, js=True, cssless=True, fail_safe=True, bypass=[], passive=False, static=True, script_types=[])

Parameters:

  • app: Flask app instance to be initiated.
  • js: Minify js or not.
  • cssless: Minify css or not.
  • fail_safe: To avoid raising error while minifying.
  • bypass: List of endpoints to bypass minifying. 
  • passive: to selectively minify routes
  • static: To enable minifying static files css, less and js.
  • script_types: List of script types to limit js minification to.

Stepwise Implementation

Step 1: Importing libraries and initializing Minify with app context.

Python3




from flask import Flask
from flask_minify import minify
  
app = Flask(__name__)
  
# initializing minify for html, js and cssless
minify(app=app, html=True, js=True, cssless=True)


Step 2: Adding route, output HTML with minified code. 

Python3




@app.route('/')
def sample_minify():
    return """<!doctype html>
<html lang=en-us prefix="og: http://ogp.me/ns#">
<meta charset=utf-8>
<meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1">
<meta name=description content="A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.">
<link rel="shortcut icon" href=https://media.geeksforgeeks.org/wp-content/cdn-uploads/gfg_favicon.png type=image/x-icon>
<meta name=theme-color content="#308D46">
<meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
<script defer src=https://apis.google.com/js/platform.js></script>
<script async src=//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.14/require.min.js></script>
<script async src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
<link rel=stylesheet href=https://use.typekit.net/mrg0hpc.css>
<title>GeeksforGeeks | A computer science portal for geeks</title>
<link rel=profile href=http://gmpg.org/xfn/11>
<link rel=pingback href>
<script type=application/ld+json>
    <span>Python Tutorial</span>
    <span class="gfg-icon gfg-icon_arrow-right"></span></a></ul></div></div></div></div><div class="side--container mb-30"><div class=card-layout><div class=heading><div class=def-title_wrap><div class=title>Featured Articles</div><a href=https://www.geeksforgeeks.org/featured-articles class=vall><span>View All</span>
    <span class="gfg-icon gfg-icon_arrow-right_filled"></span></a></div></div><div class=rightbar--articles_container><div class=content-wrapper><ul class="content-wrapper content-wrapper_links"><li><a href="https://www.geeksforgeeks.org/must-do-coding-questions-for-product-based-companies/?ref=grb" title="Permalink to Must Do Coding Questions for Product Based Companies" rel=bookmark>Must Do Coding Questions for Product Based Companies</a>
<p>May 16, 2021<li><a href="https://www.geeksforgeeks.org/must-do-coding-questions-for-companies-like-amazon-microsoft-adobe/?ref=grb" title="Permalink to Must Do Coding Questions for Companies like Amazon, Microsoft, Adobe, …" rel=bookmark>Must Do Coding Questions for Companies like Amazon, Microsoft, Adobe, …</a>
<p>May 16, 2021<li><a href="https://www.geeksforgeeks.org/progeek-cup-2021-a-project-competition-by-geeksforgeeks/?ref=grb" title="Permalink to ProGeek Cup 2021 – A Project Competition By GeeksforGeeks" rel=bookmark>ProGeek Cup 2021 – A Project Competition By GeeksforGeeks</a>
<p>May 11, 2021<li><a href="https://www.geeksforgeeks.org/recently-asked-interview-questions-in-product-based-companies/?ref=grb" title="Permalink to Recently Asked Interview Questions in Product Based Companies" rel=bookmark>Recently Asked Interview Questions in Product Based Companies</a>
<p>May 11, 2021<li><a href="https://www.geeksforgeeks.org/bridge-the-gap-between-engineering-and-your-dream-job-complete-interview-preparation/?ref=grb" title="Permalink to Bridge the Gap Between Engineering and Your Dream Job – Complete Interview Preparation" rel=bookmark>Bridge the Gap Between Engineering and Your Dream Job – Complete Interview Preparation</a>
<p>May 1, 2021</ul></div></div></div></div><div class="side--container mb-30"><div id=secondary class=widget-area role=complementary><aside id=text-15 class="widget widget_text"><div class=textwidget></div></aside><aside id=text-19 class="widget widget_text"><div class=textwidget><div class=heading><div class=def-title_wrap><div class=title>What’s New</div></div></div></div></aside><div class=card-layout><div class=content-wrapper><div class=side--container_wscard><a href="https://www.geeksforgeeks.org/courses/dsa-self-paced?utm_source=geeksforgeeks&utm_medium=article&utm_campaign=gfg_article_dsa_content_bottom"><div class=card-content><div class=thumbnail><img src=https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210203145720/DSA-SP_1-min.png class=img-fluid alt="DSA Self Paced Course"></div><div class=content><div class=head>DSA Self Paced Course</div><div class=ref>View Details</div></div></div></a></div></div></div><div class=card-layout><div class=content-wrapper><div class=side--container_wscard style=margin-top:-20px><a href="https://premium.geeksforgeeks.org/premium-plans/?utm_source=geeksforgeeks&utm_medium=article&utm_campaign=gfg_article_premium_content_bottom"><div class=card-content><div class=thumbnail><img src=https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210115220210/prethumb_min.png class=img-fluid alt="Ad free experience with GeeksforGeeks Premium"></div><div class=content><div class=head>Ad free experience with GeeksforGeeks Premium</div><div class=ref>View Details</div></div></div></a></div></div></div><aside id=text-16 class="widget widget_text"><div class=textwidget></div></aside><aside id=text-17 class="widget widget_text"><div class=textwidget></div></aside><aside id=text-18 class="widget widget_text"><div class=textwidget></div></aside></div></div><div class="side--container mb-30"><div class=card-layout><div class=heading><div class=def-title_wrap><div class=title>Recommended</div></div></div><div class=content-wrapper><div class=item-container><ul class="ql-list recommended"><li class=ql-list_item><a href="https://www.geeksforgeeks.org/category/guestblogs/?ref=grb" class=no-hover><span data-icon=one></span><span class="gfg-icon gfg-icon_arrow-right">Guest Blogs</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/must-coding-questions-company-wise/?ref=grb" class=no-hover><span data-icon=two></span><span class="gfg-icon gfg-icon_arrow-right">Must Do Coding Questions
    Company-wise</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/practice-for-cracking-any-coding-interview/?ref=grb" class=no-hover><span data-icon=three></span><span class="gfg-icon gfg-icon_arrow-right">Practice for cracking any coding
    interview</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/placements-gq/?ref=grb" class=no-hover><span data-icon=four></span><span class="gfg-icon gfg-icon_arrow-right">Placements</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/courses/cip-da/?ref=grb" class=no-hover><span data-icon=five></span><span class="gfg-icon gfg-icon_arrow-right">Complete Interview Preparation With
    Doubt Assistance</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/gate-cs-notes-gq/?ref=grb" class=no-hover><span data-icon=six></span><span class="gfg-icon gfg-icon_arrow-right">GATE CS Notes according to GATE 2021
    syllabus</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/machine-learning/?ref=grb" class=no-hover><span data-icon=seven></span><span class="gfg-icon gfg-icon_arrow-right">Machine Learning</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/django-tutorial/?ref=grb" class=no-hover><span data-icon=eight></span><span class="gfg-icon gfg-icon_arrow-right">Django Tutorial</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/computer-science-projects/?ref=grb" class=no-hover><span data-icon=nine></span><span class="gfg-icon gfg-icon_arrow-right">Computer Science Projects</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/courses/Amazon-Test-Series/?ref=grb" class=no-hover><span data-icon=ten></span><span class="gfg-icon gfg-icon_arrow-right">Amazon SDE Test Series</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/company-interview-corner/?ref=grb" class=no-hover><span data-icon=eleven></span><span class="gfg-icon gfg-icon_arrow-right">Company Interview Corner</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/the-c-standard-template-library-stl/?ref=grb" class=no-hover><span data-icon=twelve></span><span class="gfg-icon gfg-icon_arrow-right">The C++ Standard Template Library
    (STL)</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/software-design-patterns/?ref=grb" class=no-hover><span data-icon=thirteen></span><span class="gfg-icon gfg-icon_arrow-right">Software Design Patterns</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/sql-tutorial/?ref=grb" class=no-hover><span data-icon=fourteen></span><span class="gfg-icon gfg-icon_arrow-right">SQL Tutorial</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/advanced-data-structures/?ref=grb" class=no-hover><span data-icon=fifteen></span><span class="gfg-icon gfg-icon_arrow-right">Advanced Data Structures</span></a></ul></div></div></div></div></div></div></div></div><footer class=gfg-footer id=gfg-footer><div class=footer-wrapper><div class=footer-wrapper_branding><a class=footer-wrapper_branding-anchor href=https://www.geeksforgeeks.org/><img class=footer-wrapper_branding-nlogo src=https://media.geeksforgeeks.org/wp-content/cdn-uploads/logo-new-2.svg alt=GeeksforGeeks></a><div class=footer-wrapper_branding-address><i class="gfg-icon gfg-icon_pin"></i>
    <span>5th Floor, A-118,<br>Sector-136, Noida, Uttar Pradesh - 201305</span></div><div class=footer-wrapper_branding-email><i class="gfg-icon gfg-icon_mail"></i>
    <a href=mailto:feedback@geeksforgeeks.org>feedback@geeksforgeeks.org</a></div><div class=footer-wrapper_branding-social><a href=https://www.facebook.com/geeksforgeeks.org/ rel="noopener noreferrer" aria-label="GeeksforGeeks Facebook" target=_blank><div class=facebook></div></a><a href=https://www.instagram.com/geeks_for_geeks/ rel="noopener noreferrer" aria-label="GeeksforGeeks Instagram" target=_blank><div class=instagram></div></a><a href=https://in.linkedin.com/company/geeksforgeeks rel="noopener noreferrer" aria-label="GeeksforGeeks LinkedIn" target=_blank><div class=linkedin></div></a><a href=https://twitter.com/geeksforgeeks rel="noopener noreferrer" aria-label="GeeksforGeeks Twitter" target=_blank><div class=twitter></div></a><a href=https://www.youtube.com/geeksforgeeksvideos rel="noopener noreferrer" aria-label="GeeksforGeeks YouTube" target=_blank><div class=youtube></div></a></div></div><div class=footer-wrapper_links><ul class=footer-wrapper_links-list><li>Company<li><a href=https://www.geeksforgeeks.org/about/>About Us</a><li><a href=https://www.geeksforgeeks.org/careers/>Careers</a><li><a href=https://www.geeksforgeeks.org/privacy-policy/>Privacy Policy</a><li><a href=https://www.geeksforgeeks.org/about/contact-us/>Contact Us</a><li><a href=https://www.geeksforgeeks.org/copyright-information/>Copyright Policy</a></ul><ul class=footer-wrapper_links-list><li>Learn<li><a href=https://www.geeksforgeeks.org/fundamentals-of-algorithms/>Algorithms</a><li><a href=https://www.geeksforgeeks.org/data-structures/>Data Structures</a><li><a href=https://www.geeksforgeeks.org/category/program-output/>Languages</a><li><a href=https://www.geeksforgeeks.org/articles-on-computer-science-subjects-gq/>CS
    Subjects</a><li><a href=https://www.youtube.com/geeksforgeeksvideos/>Video Tutorials</a></ul><ul class=footer-wrapper_links-list><li>Practice<li><a href=https://www.geeksforgeeks.org/courses/>Courses</a><li><a href=https://practice.geeksforgeeks.org/company-tags/>Company-wise</a><li><a href=https://practice.geeksforgeeks.org/topic-tags/>Topic-wise</a><li><a href=https://practice.geeksforgeeks.org/faq.php>How to begin?</a></ul><ul class=footer-wrapper_links-list><li>Contribute<li><a href=https://www.geeksforgeeks.org/contribute/>Write an Article</a><li><a href=https://www.geeksforgeeks.org/write-interview-experience/>Write Interview
    Experience</a><li><a href="https://www.geeksforgeeks.org/careers/?job_type=1">Internships</a><li><a href=https://www.geeksforgeeks.org/how-to-contribute-videos-to-geeksforgeeks/>Videos</a></ul></div></div><div class=footer-strip><div class=copyright><a href=https://www.geeksforgeeks.org/ rel="noopener noreferrer" target=_blank>@geeksforgeeks</a>
    <span>, <a href=https://www.geeksforgeeks.org/copyright-information/>Some rights reserved</a></span></div><div class=social-links></div></div></footer></div><script src="https://www.geeksforgeeks.org/wp-includes/js/wp-embed.min.js?ver=4.9.8">
</script>
<script>
    jQuery(document).ready(function($) { RESPONSIVEUI.responsiveTabs(); })
</script>
<div class="cookie-consent hide-consent"><span class=cookie-text>We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
<a href=https://www.geeksforgeeks.org/cookie-policy/ target=_blank><u>Cookie Policy</u></a> &
        <a href=https://www.geeksforgeeks.org/privacy-policy/ target=_blank><u>Privacy Policy</u></a></span>
    <button class=consent-btn>Got It !</button>
</div>
<div class=lightbox-target>
    <img id=lightbox-image src alt=Lightbox>
<span class=lightbox-close></span>
</div>
<script>
    var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-12148232-1']);
      _gaq.push(['_trackPageview']);
      
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();
</script>"""


Step 3 : Running application 

Python3




if __name__ == "__main__":
      app.run()


Output : 

Example 2: Applying minification to some routes

In this, we can perform minification on only required routes not all, as per requirements. This is done by passing “passive=True” while passing context.

Python3




from flask import Flask
from flask_minify import minify, decorators
  
app = Flask(__name__)
  
# passive = True, just performs minification to required routes
minify(app=app, passive=True)
  
# minifies this route
@app.route('/')
@decorators.minify(html=True, js=True, cssless=True)
def sample_minify():
    return """<!doctype html>
<html lang=en-us prefix="og: http://ogp.me/ns#">
<meta charset=utf-8>
<meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1">
<meta name=description content="A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.">
<link rel="shortcut icon" href=https://media.geeksforgeeks.org/wp-content/cdn-uploads/gfg_favicon.png type=image/x-icon>
<meta name=theme-color content="#308D46">
<meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
<script defer src=https://apis.google.com/js/platform.js></script>
<script async src=//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.14/require.min.js></script>
<script async src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
<link rel=stylesheet href=https://use.typekit.net/mrg0hpc.css>
<title>GeeksforGeeks | A computer science portal for geeks</title>
<link rel=profile href=http://gmpg.org/xfn/11>
<link rel=pingback href>
<script type=application/ld+json>
    <span>Python Tutorial</span>
    <span class="gfg-icon gfg-icon_arrow-right"></span></a></ul></div></div></div></div><div class="side--container mb-30"><div class=card-layout><div class=heading><div class=def-title_wrap><div class=title>Featured Articles</div><a href=https://www.geeksforgeeks.org/featured-articles class=vall><span>View All</span>
    <span class="gfg-icon gfg-icon_arrow-right_filled"></span></a></div></div><div class=rightbar--articles_container><div class=content-wrapper><ul class="content-wrapper content-wrapper_links"><li><a href="https://www.geeksforgeeks.org/must-do-coding-questions-for-product-based-companies/?ref=grb" title="Permalink to Must Do Coding Questions for Product Based Companies" rel=bookmark>Must Do Coding Questions for Product Based Companies</a>
<p>May 16, 2021<li><a href="https://www.geeksforgeeks.org/must-do-coding-questions-for-companies-like-amazon-microsoft-adobe/?ref=grb" title="Permalink to Must Do Coding Questions for Companies like Amazon, Microsoft, Adobe, …" rel=bookmark>Must Do Coding Questions for Companies like Amazon, Microsoft, Adobe, …</a>
<p>May 16, 2021<li><a href="https://www.geeksforgeeks.org/progeek-cup-2021-a-project-competition-by-geeksforgeeks/?ref=grb" title="Permalink to ProGeek Cup 2021 – A Project Competition By GeeksforGeeks" rel=bookmark>ProGeek Cup 2021 – A Project Competition By GeeksforGeeks</a>
<p>May 11, 2021<li><a href="https://www.geeksforgeeks.org/recently-asked-interview-questions-in-product-based-companies/?ref=grb" title="Permalink to Recently Asked Interview Questions in Product Based Companies" rel=bookmark>Recently Asked Interview Questions in Product Based Companies</a>
<p>May 11, 2021<li><a href="https://www.geeksforgeeks.org/bridge-the-gap-between-engineering-and-your-dream-job-complete-interview-preparation/?ref=grb" title="Permalink to Bridge the Gap Between Engineering and Your Dream Job – Complete Interview Preparation" rel=bookmark>Bridge the Gap Between Engineering and Your Dream Job – Complete Interview Preparation</a>
<p>May 1, 2021</ul></div></div></div></div><div class="side--container mb-30"><div id=secondary class=widget-area role=complementary><aside id=text-15 class="widget widget_text"><div class=textwidget></div></aside><aside id=text-19 class="widget widget_text"><div class=textwidget><div class=heading><div class=def-title_wrap><div class=title>What’s New</div></div></div></div></aside><div class=card-layout><div class=content-wrapper><div class=side--container_wscard><a href="https://www.geeksforgeeks.org/courses/dsa-self-paced?utm_source=geeksforgeeks&utm_medium=article&utm_campaign=gfg_article_dsa_content_bottom"><div class=card-content><div class=thumbnail><img src=https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210203145720/DSA-SP_1-min.png class=img-fluid alt="DSA Self Paced Course"></div><div class=content><div class=head>DSA Self Paced Course</div><div class=ref>View Details</div></div></div></a></div></div></div><div class=card-layout><div class=content-wrapper><div class=side--container_wscard style=margin-top:-20px><a href="https://premium.geeksforgeeks.org/premium-plans/?utm_source=geeksforgeeks&utm_medium=article&utm_campaign=gfg_article_premium_content_bottom"><div class=card-content><div class=thumbnail><img src=https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210115220210/prethumb_min.png class=img-fluid alt="Ad free experience with GeeksforGeeks Premium"></div><div class=content><div class=head>Ad free experience with GeeksforGeeks Premium</div><div class=ref>View Details</div></div></div></a></div></div></div><aside id=text-16 class="widget widget_text"><div class=textwidget></div></aside><aside id=text-17 class="widget widget_text"><div class=textwidget></div></aside><aside id=text-18 class="widget widget_text"><div class=textwidget></div></aside></div></div><div class="side--container mb-30"><div class=card-layout><div class=heading><div class=def-title_wrap><div class=title>Recommended</div></div></div><div class=content-wrapper><div class=item-container><ul class="ql-list recommended"><li class=ql-list_item><a href="https://www.geeksforgeeks.org/category/guestblogs/?ref=grb" class=no-hover><span data-icon=one></span><span class="gfg-icon gfg-icon_arrow-right">Guest Blogs</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/must-coding-questions-company-wise/?ref=grb" class=no-hover><span data-icon=two></span><span class="gfg-icon gfg-icon_arrow-right">Must Do Coding Questions
    Company-wise</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/practice-for-cracking-any-coding-interview/?ref=grb" class=no-hover><span data-icon=three></span><span class="gfg-icon gfg-icon_arrow-right">Practice for cracking any coding
    interview</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/placements-gq/?ref=grb" class=no-hover><span data-icon=four></span><span class="gfg-icon gfg-icon_arrow-right">Placements</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/courses/cip-da/?ref=grb" class=no-hover><span data-icon=five></span><span class="gfg-icon gfg-icon_arrow-right">Complete Interview Preparation With
    Doubt Assistance</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/gate-cs-notes-gq/?ref=grb" class=no-hover><span data-icon=six></span><span class="gfg-icon gfg-icon_arrow-right">GATE CS Notes according to GATE 2021
    syllabus</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/machine-learning/?ref=grb" class=no-hover><span data-icon=seven></span><span class="gfg-icon gfg-icon_arrow-right">Machine Learning</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/django-tutorial/?ref=grb" class=no-hover><span data-icon=eight></span><span class="gfg-icon gfg-icon_arrow-right">Django Tutorial</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/computer-science-projects/?ref=grb" class=no-hover><span data-icon=nine></span><span class="gfg-icon gfg-icon_arrow-right">Computer Science Projects</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/courses/Amazon-Test-Series/?ref=grb" class=no-hover><span data-icon=ten></span><span class="gfg-icon gfg-icon_arrow-right">Amazon SDE Test Series</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/company-interview-corner/?ref=grb" class=no-hover><span data-icon=eleven></span><span class="gfg-icon gfg-icon_arrow-right">Company Interview Corner</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/the-c-standard-template-library-stl/?ref=grb" class=no-hover><span data-icon=twelve></span><span class="gfg-icon gfg-icon_arrow-right">The C++ Standard Template Library
    (STL)</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/software-design-patterns/?ref=grb" class=no-hover><span data-icon=thirteen></span><span class="gfg-icon gfg-icon_arrow-right">Software Design Patterns</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/sql-tutorial/?ref=grb" class=no-hover><span data-icon=fourteen></span><span class="gfg-icon gfg-icon_arrow-right">SQL Tutorial</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/advanced-data-structures/?ref=grb" class=no-hover><span data-icon=fifteen></span><span class="gfg-icon gfg-icon_arrow-right">Advanced Data Structures</span></a></ul></div></div></div></div></div></div></div></div><footer class=gfg-footer id=gfg-footer><div class=footer-wrapper><div class=footer-wrapper_branding><a class=footer-wrapper_branding-anchor href=https://www.geeksforgeeks.org/><img class=footer-wrapper_branding-nlogo src=https://media.geeksforgeeks.org/wp-content/cdn-uploads/logo-new-2.svg alt=GeeksforGeeks></a><div class=footer-wrapper_branding-address><i class="gfg-icon gfg-icon_pin"></i>
    <span>5th Floor, A-118,<br>Sector-136, Noida, Uttar Pradesh - 201305</span></div><div class=footer-wrapper_branding-email><i class="gfg-icon gfg-icon_mail"></i>
    <a href=mailto:feedback@geeksforgeeks.org>feedback@geeksforgeeks.org</a></div><div class=footer-wrapper_branding-social><a href=https://www.facebook.com/geeksforgeeks.org/ rel="noopener noreferrer" aria-label="GeeksforGeeks Facebook" target=_blank><div class=facebook></div></a><a href=https://www.instagram.com/geeks_for_geeks/ rel="noopener noreferrer" aria-label="GeeksforGeeks Instagram" target=_blank><div class=instagram></div></a><a href=https://in.linkedin.com/company/geeksforgeeks rel="noopener noreferrer" aria-label="GeeksforGeeks LinkedIn" target=_blank><div class=linkedin></div></a><a href=https://twitter.com/geeksforgeeks rel="noopener noreferrer" aria-label="GeeksforGeeks Twitter" target=_blank><div class=twitter></div></a><a href=https://www.youtube.com/geeksforgeeksvideos rel="noopener noreferrer" aria-label="GeeksforGeeks YouTube" target=_blank><div class=youtube></div></a></div></div><div class=footer-wrapper_links><ul class=footer-wrapper_links-list><li>Company<li><a href=https://www.geeksforgeeks.org/about/>About Us</a><li><a href=https://www.geeksforgeeks.org/careers/>Careers</a><li><a href=https://www.geeksforgeeks.org/privacy-policy/>Privacy Policy</a><li><a href=https://www.geeksforgeeks.org/about/contact-us/>Contact Us</a><li><a href=https://www.geeksforgeeks.org/copyright-information/>Copyright Policy</a></ul><ul class=footer-wrapper_links-list><li>Learn<li><a href=https://www.geeksforgeeks.org/fundamentals-of-algorithms/>Algorithms</a><li><a href=https://www.geeksforgeeks.org/data-structures/>Data Structures</a><li><a href=https://www.geeksforgeeks.org/category/program-output/>Languages</a><li><a href=https://www.geeksforgeeks.org/articles-on-computer-science-subjects-gq/>CS
    Subjects</a><li><a href=https://www.youtube.com/geeksforgeeksvideos/>Video Tutorials</a></ul><ul class=footer-wrapper_links-list><li>Practice<li><a href=https://www.geeksforgeeks.org/courses/>Courses</a><li><a href=https://practice.geeksforgeeks.org/company-tags/>Company-wise</a><li><a href=https://practice.geeksforgeeks.org/topic-tags/>Topic-wise</a><li><a href=https://practice.geeksforgeeks.org/faq.php>How to begin?</a></ul><ul class=footer-wrapper_links-list><li>Contribute<li><a href=https://www.geeksforgeeks.org/contribute/>Write an Article</a><li><a href=https://www.geeksforgeeks.org/write-interview-experience/>Write Interview
    Experience</a><li><a href="https://www.geeksforgeeks.org/careers/?job_type=1">Internships</a><li><a href=https://www.geeksforgeeks.org/how-to-contribute-videos-to-geeksforgeeks/>Videos</a></ul></div></div><div class=footer-strip><div class=copyright><a href=https://www.geeksforgeeks.org/ rel="noopener noreferrer" target=_blank>@geeksforgeeks</a>
    <span>, <a href=https://www.geeksforgeeks.org/copyright-information/>Some rights reserved</a></span></div><div class=social-links></div></div></footer></div><script src="https://www.geeksforgeeks.org/wp-includes/js/wp-embed.min.js?ver=4.9.8">
</script>
<script>
    jQuery(document).ready(function($) { RESPONSIVEUI.responsiveTabs(); })
</script>
<div class="cookie-consent hide-consent"><span class=cookie-text>We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
<a href=https://www.geeksforgeeks.org/cookie-policy/ target=_blank><u>Cookie Policy</u></a> &
        <a href=https://www.geeksforgeeks.org/privacy-policy/ target=_blank><u>Privacy Policy</u></a></span>
    <button class=consent-btn>Got It !</button>
</div>
<div class=lightbox-target>
    <img id=lightbox-image src alt=Lightbox>
<span class=lightbox-close></span>
</div>
<script>
    var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-12148232-1']);
      _gaq.push(['_trackPageview']);
  
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();
</script>"""
  
# doesn't minify this route
@app.route('/no_mini')
def no_minify():
    return """<!doctype html>
<html lang=en-us prefix="og: http://ogp.me/ns#">
<meta charset=utf-8>
<meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1">
<meta name=description content="A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.">
<link rel="shortcut icon" href=https://media.geeksforgeeks.org/wp-content/cdn-uploads/gfg_favicon.png type=image/x-icon>
<meta name=theme-color content="#308D46">
<meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
<script defer src=https://apis.google.com/js/platform.js></script>
<script async src=//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.14/require.min.js></script>
<script async src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
<link rel=stylesheet href=https://use.typekit.net/mrg0hpc.css>
<title>GeeksforGeeks | A computer science portal for geeks</title>
<link rel=profile href=http://gmpg.org/xfn/11>
<link rel=pingback href>
<script type=application/ld+json>
    <span>Python Tutorial</span>
    <span class="gfg-icon gfg-icon_arrow-right"></span></a></ul></div></div></div></div><div class="side--container mb-30"><div class=card-layout><div class=heading><div class=def-title_wrap><div class=title>Featured Articles</div><a href=https://www.geeksforgeeks.org/featured-articles class=vall><span>View All</span>
    <span class="gfg-icon gfg-icon_arrow-right_filled"></span></a></div></div><div class=rightbar--articles_container><div class=content-wrapper><ul class="content-wrapper content-wrapper_links"><li><a href="https://www.geeksforgeeks.org/must-do-coding-questions-for-product-based-companies/?ref=grb" title="Permalink to Must Do Coding Questions for Product Based Companies" rel=bookmark>Must Do Coding Questions for Product Based Companies</a>
<p>May 16, 2021<li><a href="https://www.geeksforgeeks.org/must-do-coding-questions-for-companies-like-amazon-microsoft-adobe/?ref=grb" title="Permalink to Must Do Coding Questions for Companies like Amazon, Microsoft, Adobe, …" rel=bookmark>Must Do Coding Questions for Companies like Amazon, Microsoft, Adobe, …</a>
<p>May 16, 2021<li><a href="https://www.geeksforgeeks.org/progeek-cup-2021-a-project-competition-by-geeksforgeeks/?ref=grb" title="Permalink to ProGeek Cup 2021 – A Project Competition By GeeksforGeeks" rel=bookmark>ProGeek Cup 2021 – A Project Competition By GeeksforGeeks</a>
<p>May 11, 2021<li><a href="https://www.geeksforgeeks.org/recently-asked-interview-questions-in-product-based-companies/?ref=grb" title="Permalink to Recently Asked Interview Questions in Product Based Companies" rel=bookmark>Recently Asked Interview Questions in Product Based Companies</a>
<p>May 11, 2021<li><a href="https://www.geeksforgeeks.org/bridge-the-gap-between-engineering-and-your-dream-job-complete-interview-preparation/?ref=grb" title="Permalink to Bridge the Gap Between Engineering and Your Dream Job – Complete Interview Preparation" rel=bookmark>Bridge the Gap Between Engineering and Your Dream Job – Complete Interview Preparation</a>
<p>May 1, 2021</ul></div></div></div></div><div class="side--container mb-30"><div id=secondary class=widget-area role=complementary><aside id=text-15 class="widget widget_text"><div class=textwidget></div></aside><aside id=text-19 class="widget widget_text"><div class=textwidget><div class=heading><div class=def-title_wrap><div class=title>What’s New</div></div></div></div></aside><div class=card-layout><div class=content-wrapper><div class=side--container_wscard><a href="https://www.geeksforgeeks.org/courses/dsa-self-paced?utm_source=geeksforgeeks&utm_medium=article&utm_campaign=gfg_article_dsa_content_bottom"><div class=card-content><div class=thumbnail><img src=https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210203145720/DSA-SP_1-min.png class=img-fluid alt="DSA Self Paced Course"></div><div class=content><div class=head>DSA Self Paced Course</div><div class=ref>View Details</div></div></div></a></div></div></div><div class=card-layout><div class=content-wrapper><div class=side--container_wscard style=margin-top:-20px><a href="https://premium.geeksforgeeks.org/premium-plans/?utm_source=geeksforgeeks&utm_medium=article&utm_campaign=gfg_article_premium_content_bottom"><div class=card-content><div class=thumbnail><img src=https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210115220210/prethumb_min.png class=img-fluid alt="Ad free experience with GeeksforGeeks Premium"></div><div class=content><div class=head>Ad free experience with GeeksforGeeks Premium</div><div class=ref>View Details</div></div></div></a></div></div></div><aside id=text-16 class="widget widget_text"><div class=textwidget></div></aside><aside id=text-17 class="widget widget_text"><div class=textwidget></div></aside><aside id=text-18 class="widget widget_text"><div class=textwidget></div></aside></div></div><div class="side--container mb-30"><div class=card-layout><div class=heading><div class=def-title_wrap><div class=title>Recommended</div></div></div><div class=content-wrapper><div class=item-container><ul class="ql-list recommended"><li class=ql-list_item><a href="https://www.geeksforgeeks.org/category/guestblogs/?ref=grb" class=no-hover><span data-icon=one></span><span class="gfg-icon gfg-icon_arrow-right">Guest Blogs</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/must-coding-questions-company-wise/?ref=grb" class=no-hover><span data-icon=two></span><span class="gfg-icon gfg-icon_arrow-right">Must Do Coding Questions
    Company-wise</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/practice-for-cracking-any-coding-interview/?ref=grb" class=no-hover><span data-icon=three></span><span class="gfg-icon gfg-icon_arrow-right">Practice for cracking any coding
    interview</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/placements-gq/?ref=grb" class=no-hover><span data-icon=four></span><span class="gfg-icon gfg-icon_arrow-right">Placements</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/courses/cip-da/?ref=grb" class=no-hover><span data-icon=five></span><span class="gfg-icon gfg-icon_arrow-right">Complete Interview Preparation With
    Doubt Assistance</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/gate-cs-notes-gq/?ref=grb" class=no-hover><span data-icon=six></span><span class="gfg-icon gfg-icon_arrow-right">GATE CS Notes according to GATE 2021
    syllabus</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/machine-learning/?ref=grb" class=no-hover><span data-icon=seven></span><span class="gfg-icon gfg-icon_arrow-right">Machine Learning</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/django-tutorial/?ref=grb" class=no-hover><span data-icon=eight></span><span class="gfg-icon gfg-icon_arrow-right">Django Tutorial</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/computer-science-projects/?ref=grb" class=no-hover><span data-icon=nine></span><span class="gfg-icon gfg-icon_arrow-right">Computer Science Projects</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/courses/Amazon-Test-Series/?ref=grb" class=no-hover><span data-icon=ten></span><span class="gfg-icon gfg-icon_arrow-right">Amazon SDE Test Series</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/company-interview-corner/?ref=grb" class=no-hover><span data-icon=eleven></span><span class="gfg-icon gfg-icon_arrow-right">Company Interview Corner</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/the-c-standard-template-library-stl/?ref=grb" class=no-hover><span data-icon=twelve></span><span class="gfg-icon gfg-icon_arrow-right">The C++ Standard Template Library
    (STL)</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/software-design-patterns/?ref=grb" class=no-hover><span data-icon=thirteen></span><span class="gfg-icon gfg-icon_arrow-right">Software Design Patterns</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/sql-tutorial/?ref=grb" class=no-hover><span data-icon=fourteen></span><span class="gfg-icon gfg-icon_arrow-right">SQL Tutorial</span></a><li class=ql-list_item><a href="https://www.geeksforgeeks.org/advanced-data-structures/?ref=grb" class=no-hover><span data-icon=fifteen></span><span class="gfg-icon gfg-icon_arrow-right">Advanced Data Structures</span></a></ul></div></div></div></div></div></div></div></div><footer class=gfg-footer id=gfg-footer><div class=footer-wrapper><div class=footer-wrapper_branding><a class=footer-wrapper_branding-anchor href=https://www.geeksforgeeks.org/><img class=footer-wrapper_branding-nlogo src=https://media.geeksforgeeks.org/wp-content/cdn-uploads/logo-new-2.svg alt=GeeksforGeeks></a><div class=footer-wrapper_branding-address><i class="gfg-icon gfg-icon_pin"></i>
    <span>5th Floor, A-118,<br>Sector-136, Noida, Uttar Pradesh - 201305</span></div><div class=footer-wrapper_branding-email><i class="gfg-icon gfg-icon_mail"></i>
    <a href=mailto:feedback@geeksforgeeks.org>feedback@geeksforgeeks.org</a></div><div class=footer-wrapper_branding-social><a href=https://www.facebook.com/geeksforgeeks.org/ rel="noopener noreferrer" aria-label="GeeksforGeeks Facebook" target=_blank><div class=facebook></div></a><a href=https://www.instagram.com/geeks_for_geeks/ rel="noopener noreferrer" aria-label="GeeksforGeeks Instagram" target=_blank><div class=instagram></div></a><a href=https://in.linkedin.com/company/geeksforgeeks rel="noopener noreferrer" aria-label="GeeksforGeeks LinkedIn" target=_blank><div class=linkedin></div></a><a href=https://twitter.com/geeksforgeeks rel="noopener noreferrer" aria-label="GeeksforGeeks Twitter" target=_blank><div class=twitter></div></a><a href=https://www.youtube.com/geeksforgeeksvideos rel="noopener noreferrer" aria-label="GeeksforGeeks YouTube" target=_blank><div class=youtube></div></a></div></div><div class=footer-wrapper_links><ul class=footer-wrapper_links-list><li>Company<li><a href=https://www.geeksforgeeks.org/about/>About Us</a><li><a href=https://www.geeksforgeeks.org/careers/>Careers</a><li><a href=https://www.geeksforgeeks.org/privacy-policy/>Privacy Policy</a><li><a href=https://www.geeksforgeeks.org/about/contact-us/>Contact Us</a><li><a href=https://www.geeksforgeeks.org/copyright-information/>Copyright Policy</a></ul><ul class=footer-wrapper_links-list><li>Learn<li><a href=https://www.geeksforgeeks.org/fundamentals-of-algorithms/>Algorithms</a><li><a href=https://www.geeksforgeeks.org/data-structures/>Data Structures</a><li><a href=https://www.geeksforgeeks.org/category/program-output/>Languages</a><li><a href=https://www.geeksforgeeks.org/articles-on-computer-science-subjects-gq/>CS
    Subjects</a><li><a href=https://www.youtube.com/geeksforgeeksvideos/>Video Tutorials</a></ul><ul class=footer-wrapper_links-list><li>Practice<li><a href=https://www.geeksforgeeks.org/courses/>Courses</a><li><a href=https://practice.geeksforgeeks.org/company-tags/>Company-wise</a><li><a href=https://practice.geeksforgeeks.org/topic-tags/>Topic-wise</a><li><a href=https://practice.geeksforgeeks.org/faq.php>How to begin?</a></ul><ul class=footer-wrapper_links-list><li>Contribute<li><a href=https://www.geeksforgeeks.org/contribute/>Write an Article</a><li><a href=https://www.geeksforgeeks.org/write-interview-experience/>Write Interview
    Experience</a><li><a href="https://www.geeksforgeeks.org/careers/?job_type=1">Internships</a><li><a href=https://www.geeksforgeeks.org/how-to-contribute-videos-to-geeksforgeeks/>Videos</a></ul></div></div><div class=footer-strip><div class=copyright><a href=https://www.geeksforgeeks.org/ rel="noopener noreferrer" target=_blank>@geeksforgeeks</a>
    <span>, <a href=https://www.geeksforgeeks.org/copyright-information/>Some rights reserved</a></span></div><div class=social-links></div></div></footer></div><script src="https://www.geeksforgeeks.org/wp-includes/js/wp-embed.min.js?ver=4.9.8">
</script>
<script>
    jQuery(document).ready(function($) { RESPONSIVEUI.responsiveTabs(); })
</script>
<div class="cookie-consent hide-consent"><span class=cookie-text>We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
<a href=https://www.geeksforgeeks.org/cookie-policy/ target=_blank><u>Cookie Policy</u></a> &
        <a href=https://www.geeksforgeeks.org/privacy-policy/ target=_blank><u>Privacy Policy</u></a></span>
    <button class=consent-btn>Got It !</button>
</div>
<div class=lightbox-target>
    <img id=lightbox-image src alt=Lightbox>
<span class=lightbox-close></span>
</div>
<script>
    var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-12148232-1']);
      _gaq.push(['_trackPageview']);
  
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();
</script>"""
  
  
if __name__ == "__main__":
      app.run()


Output : 



Similar Reads

Documenting Flask Endpoint using Flask-Autodoc
Documentation of endpoints is an essential task in web development and being able to apply it in different frameworks is always a utility. This article discusses how endpoints in Flask can be decorated to generate good documentation of them using the Flask-Autodoc module. This module provides the following features - Helps to document endpoints of
4 min read
How to use Flask-Session in Python Flask ?
Flask Session - Flask-Session is an extension for Flask that supports Server-side Session to your application.The Session is the time between the client logs in to the server and logs out of the server.The data that is required to be saved in the Session is stored in a temporary directory on the server.The data in the Session is stored on the top o
4 min read
How to Integrate Flask-Admin and Flask-Login
In order to merge the admin and login pages, we can utilize a short form or any other login method that only requires the username and password. This is known as integrating the admin page and Flask login since it simply redirects users to the admin page when they log in. Let's is how to implement this in this article. Integrate Flask Admin and Fla
8 min read
Flask URL Helper Function - Flask url_for()
In this article, we are going to learn about the flask url_for() function of the flask URL helper in Python. Flask is a straightforward, speedy, scalable library, used for building, compact web applications. It is a micro framework, that presents developers, useful tools, and, features, for coding REST APIs, and backend data processing, of web apps
12 min read
Retrieving HTML Form data using Flask
Flask is a lightweight WSGI web application framework. It is designed to make getting started quick and easy, with the ability to scale up to complex applications. It began as a simple wrapper around Werkzeug and Jinja and has become one of the most popular Python web application frameworks. Read this article to know more about Flask Create form as
3 min read
Convert CSV to HTML Table using Python Pandas and Flask Framework
In this article, we are going to convert a CSV file into an HTML table using Python Pandas and Flask Framework. Sample CSV file : USERNAME,IDENTIFIER,FIRST_NAME,LAST_NAME booker12,9012,Rachel,Booker grey07,2070,Laura,Grey johnson81,4081,Craig,Johnson jenkins46,9346,Mary,Jenkins smith79,5079,Jamie,SmithStepwise ImplementationCreating Environment Ste
2 min read
Python | Using for loop in Flask
Prerequisite: HTML Basics, Python Basics, Flask It is not possible to write front-end course every time user make changes in his/her profile. We use a template and it generates code according to the content. Flask is one of the web development frameworks written in Python. Through flask, a loop can be run in the HTML code using jinja template and a
3 min read
Setup API for GeeksforGeeks user data using WebScraping and Flask
Prerequisite: WebScraping in Python, Introduction to Flask In this post, we will discuss how to get information about a GeeksforGeeks user using web scraping and serve the information as an API using Python's micro-framework, Flask. Step #1: Visit the auth profile To scrape a website, the first step is to visit the website. Step #2: Inspect the Pag
3 min read
Python | Build a REST API using Flask
Prerequisite: Introduction to Rest API REST stands for REpresentational State Transfer and is an architectural style used in modern web development. It defines a set or rules/constraints for a web application to send and receive data. In this article, we will build a REST API in Python using the Flask framework. Flask is a popular micro framework f
3 min read
Create a Weather app using Flask | Python
Prerequisite : Flask installation Flask is a lightweight framework written in Python. It is lightweight because it does not require particular tools or libraries and allow rapid web development. today we will create a weather app using flask as a web framework. this weather web app will provide current weather updates of cities searched. Basic setu
2 min read
Article Tags :
Practice Tags :