<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Bhavya Agrawal</title>
    <description>The latest articles on DEV Community by Bhavya Agrawal (@bhavya_agrawal).</description>
    <link>https://dev.to/bhavya_agrawal</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F865221%2Fbc95245f-05b2-425e-a979-f4c775f80dcf.jpeg</url>
      <title>DEV Community: Bhavya Agrawal</title>
      <link>https://dev.to/bhavya_agrawal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bhavya_agrawal"/>
    <language>en</language>
    <item>
      <title>An introduction to the Flask Python web app framework</title>
      <dc:creator>Bhavya Agrawal</dc:creator>
      <pubDate>Fri, 20 May 2022 10:38:39 +0000</pubDate>
      <link>https://dev.to/bhavya_agrawal/an-introduction-to-the-flask-python-web-app-framework-279j</link>
      <guid>https://dev.to/bhavya_agrawal/an-introduction-to-the-flask-python-web-app-framework-279j</guid>
      <description>&lt;p&gt;&lt;code&gt;In computer programming, a software framework is an abstraction in which software, providing generic functionality, can be selectively changed by additional user-written code, thus providing application-specific software.&lt;/code&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;"-Source Wikipedia"&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Flask is a web framework. This means flask provides you with tools, libraries and technologies that allow you to build a web application. This web application can be some web pages, a blog, a wiki or go as big as a web-based calendar application or a commercial website. Flask is based on WSGI(Web Server Gateway Interface) toolkit and Jinja2 template engine.&lt;/p&gt;

&lt;p&gt;Flask makes the web development process rapid &amp;amp; easy with few lines of code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create an Simple web Application with Flask -&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Open a terminal and install Flask using PIP:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pip install Flask
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Create a file with &lt;code&gt;.py&lt;/code&gt; extension and paste below code-&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask    
app = Flask(__name__)   # Flask constructor

# A decorator used to tell the application
# which URL is associated function
@app.route('/')      
def hello():
    return 'HELLO WORLD'

if __name__=='__main__':
   app.run()
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The variable &lt;strong&gt;name&lt;/strong&gt; is passed as first argument when &lt;br&gt;
creating an instance of the Flask object (a Python Flask &lt;br&gt;
application). In this case &lt;strong&gt;name&lt;/strong&gt; represents the name of the &lt;br&gt;
application package and it’s used by Flask to identify &lt;br&gt;
resources like templates, static assets and the instance &lt;br&gt;
folder.&lt;/p&gt;

&lt;p&gt;route() decorator, to bind the URL to a function. It also &lt;br&gt;
contains &lt;code&gt;method&lt;/code&gt; keyword use to bind request method along &lt;br&gt;
with url.&lt;br&gt;
If the server get the request on the binding URL then it calls&lt;br&gt;&lt;br&gt;
the function bind to that URL.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now run the file, you will get the localhost URL and paste it in your browser.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yIe9_UtK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xrlorzsz2yi5ag1reds1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yIe9_UtK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xrlorzsz2yi5ag1reds1.jpg" alt="Image description" width="480" height="128"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project Structure in Flask&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt; PROJECT ROOT &amp;gt;
   |
   |-- app/__init__.py
   |-- app/
   |    |-- static/
   |    |    |-- &amp;lt;css, JS, images&amp;gt;         # CSS files, Javascripts files
   |    |
   |    |-- templates/
   |    |    |
   |    |    |-- includes/                 # Page chunks, components
   |    |    |    |
   |    |    |    |-- navigation.html      # Top bar
   |    |    |    |-- sidebar.html         # Left sidebar
   |    |    |    |-- scripts.html         # JS scripts common to all pages
   |    |    |    |-- footer.html          # The common footer
   |    |    |
   |    |    |-- layouts/                  # App Layouts (the master pages)
   |    |    |    |
   |    |    |    |-- base.html            # Used by common pages like index, UI
   |    |    |    |-- base-fullscreen.html # Used by auth pages (login, register)
   |    |    |
   |    |    |-- accounts/                 # Auth Pages (login, register)
   |    |    |    |
   |    |    |    |-- login.html           # Use layout `base-fullscreen.html`
   |    |    |    |-- register.html        # Use layout `base-fullscreen.html`  
   |    |    |
   |    |  index.html                      # The default page
   |    |  page-404.html                   # Error 404 page (page not found)
   |    |  page-500.html                   # Error 500 page (server error)
   |    |    *.html                        # All other pages provided by the UI Kit
   |
   |-- requirements.txt
   |
   |-- run.py
   |
   |-- ************************************************************************
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The relevant files:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;run.py&lt;/strong&gt; - the entry point used to start the application&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;requirements.txt&lt;/strong&gt; - a file that specifies all dependencies (for now is just Flask)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;app&lt;/strong&gt; - the application folder where we will add our code&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;app/_&lt;em&gt;init&lt;/em&gt;_.py&lt;/strong&gt; - This file is required to let us use the app as a Python Package&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;app/static&lt;/strong&gt; - this folder will contain design assets: JS, CSS, and images.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;templates&lt;/strong&gt; - the directory with pages, layouts, and components used by Flask to generate some nice pages for us&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>flask</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
