{"id":2179,"date":"2019-07-12T18:03:55","date_gmt":"2019-07-12T12:33:55","guid":{"rendered":"http:\/\/blog.tenthplanet.in\/?p=2179"},"modified":"2026-03-03T10:14:00","modified_gmt":"2026-03-03T10:14:00","slug":"web-app-using-python-flask","status":"publish","type":"post","link":"https:\/\/tenthplanet.in\/blogs\/web-app-using-python-flask\/","title":{"rendered":"Building a Web application using Python Flask"},"content":{"rendered":"<h3>Introduction<\/h3>\n<p>Python Flask is a micro-framework that provides functionalities to build a web application. Micro-frameworks are normally frameworks with little to no dependencies on external libraries. This has both pros and cons.<\/p>\n<h4>Pros<\/h4>\n<p>Flask framework is light, there are little dependencies and there is no need to watch for security bugs.<\/p>\n<h4>Cons<\/h4>\n<p>Sometimes you will have to do more work by yourself or increase the list of dependencies by adding plug-ins.<\/p>\n<h4>Why Flask<\/h4>\n<p>There are several python frameworks like Django, bottle, tornado, etc., but what separates Flask from all the others are:<\/p>\n<ul>\n<li>It is simple to learn and extensively scalable.<\/li>\n<li>Absence of application architectures and data abstraction layers.<\/li>\n<li>Flask is very flexible and easy to use.<\/li>\n<\/ul>\n<p>Flask takes care of the processing by receiving requests from the program and also figures out what response to send to the user. This is done using HTTP.<\/p>\n<p>Flask can also be used for connecting databases and web applications.<\/p>\n<h4>Requirement of templates while working with Flask<\/h4>\n<p>Creating mock objects is a useful technique that allows you to concentrate on one part of the application without having to worry about other parts of the system that don&#8217;t exist yet. These separate applications can be imported into our main python code by using the render_template() method from the flask framework. This method will look for HTML files in the templates folder and it will render the files which you ask for.<\/p>\n<h3>Creating basic application using Flask in Python<\/h3>\n<p>import Flask<br \/>\napp = flask.Flask(__name__)<br \/>\napp.config[&#8220;DEBUG&#8221;] = True<\/p>\n<p>@app.route(&#8216;\/&#8217;, methods=[&#8216;GET&#8217;])<br \/>\ndef home():<br \/>\nreturn &#8220;&lt;h1&gt;Flask Application&lt;\/h1&gt;&lt;p&gt;my first webapp using Flask&lt;\/p&gt;&#8221;<\/p>\n<p>app.run()<\/p>\n<p>After we run the program we get the following output:<\/p>\n<p>Running on <span style=\"text-decoration: underline\">http:\/\/127.0.0.1:5000\/<\/span> (Press CTRL+C to quit)<\/p>\n<p>When we connect to the Flask server at <span style=\"text-decoration: underline\">http:\/\/127.0.0.1:5000\/<\/span>, Flask checks if there is a match between the path provided and a defined function. Flask runs the code in the function and displays the returned result in the browser.<\/p>\n<h3>Conclusion<\/h3>\n<p>Webpage creation is easier with Python Flask, since it involves the use of HTML\/CSS, provides simplicity, flexibility &amp; fine-grained control and is extensively documented.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python&#8217;s Flask functionality can be used to create dynamic web applications.<\/p>\n","protected":false},"author":23,"featured_media":2213,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[424],"tags":[561,562,432],"class_list":["post-2179","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-pentaho","tag-flask","tag-python","tag-web-page"],"acf":[],"_links":{"self":[{"href":"https:\/\/tenthplanet.in\/blogs\/wp-json\/wp\/v2\/posts\/2179","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tenthplanet.in\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tenthplanet.in\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tenthplanet.in\/blogs\/wp-json\/wp\/v2\/users\/23"}],"replies":[{"embeddable":true,"href":"https:\/\/tenthplanet.in\/blogs\/wp-json\/wp\/v2\/comments?post=2179"}],"version-history":[{"count":0,"href":"https:\/\/tenthplanet.in\/blogs\/wp-json\/wp\/v2\/posts\/2179\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tenthplanet.in\/blogs\/wp-json\/wp\/v2\/media\/2213"}],"wp:attachment":[{"href":"https:\/\/tenthplanet.in\/blogs\/wp-json\/wp\/v2\/media?parent=2179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tenthplanet.in\/blogs\/wp-json\/wp\/v2\/categories?post=2179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tenthplanet.in\/blogs\/wp-json\/wp\/v2\/tags?post=2179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}