<?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: Hans(Akhil) Maulloo</title>
    <description>The latest articles on DEV Community by Hans(Akhil) Maulloo (@kouul).</description>
    <link>https://dev.to/kouul</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%2F375877%2F3cc11d7b-66a1-4582-b717-98e803eaa5f6.jpeg</url>
      <title>DEV Community: Hans(Akhil) Maulloo</title>
      <link>https://dev.to/kouul</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kouul"/>
    <language>en</language>
    <item>
      <title>How to deploy a FReMP Stack app to Heroku</title>
      <dc:creator>Hans(Akhil) Maulloo</dc:creator>
      <pubDate>Wed, 15 Jul 2020 06:28:06 +0000</pubDate>
      <link>https://dev.to/kouul/how-to-deploy-a-fremp-stack-app-to-heroku-12pg</link>
      <guid>https://dev.to/kouul/how-to-deploy-a-fremp-stack-app-to-heroku-12pg</guid>
      <description>&lt;p&gt;Hello Flask &amp;amp; React lovers!&lt;/p&gt;

&lt;p&gt;In my &lt;a href="https://dev.to/kouul/frmp-stack-5g9"&gt;previous article&lt;/a&gt;, I have written about What is the &lt;strong&gt;FReMP&lt;/strong&gt; Stack, How to install it on a Linux environment and a tutorial showing how to build a simple app with it. So, if you are still unsure about What is the FReMP Stack, feel free to check it out before reading this one. In this article, I will be showing you how did I deploy a FReMP Stack application on Heroku.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Heroku?
&lt;/h2&gt;

&lt;p&gt;Well simply because you want to host you application for free and want to share it to the world. You may want to see how your application would behave in a production environment. It can also be used for testing purposes. Or, you may want to record traffic for analytics on your app. There can be many reasons.&lt;/p&gt;

&lt;h2&gt;
  
  
  Before we start, it's good to know
&lt;/h2&gt;

&lt;p&gt;The FReMP Stack draws a line between your frontend and backend, that is, you will have two folders; one folder containing the code for you reactjs frontend and the other folder for your python/flask backend code. Due to that, we will create two applications on Heroku. We'll start by deploying the backend first, and this will act as a list of APIs endpoints that we will test using Postman. If all test works, we will proceed with deploying the frontend. We  will, also, use MongoDB Atlas to connect our backend application to the database. MongoDB Atlas is simply MongoDB hosted on the cloud. It facilitates connection from our app to mongodb. Enough talking and let's get to the fun part now!&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 0: Create an account on Heroku and MongoDB Atlas
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Register for an account for free on Heroku by going to &lt;a href="https://heroku.com" rel="noopener noreferrer"&gt;https://heroku.com&lt;/a&gt;. After you've created your account, create two apps and you can name them whatever you want. For this tutorial, we will use the names fe-name-app for deploying our frontend code and be-name-app for deploying our backend code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Register for an account for free on Atlas Mongodb by going to &lt;a href="https://cloud.mongodb.com" rel="noopener noreferrer"&gt;https://cloud.mongodb.com&lt;/a&gt;. Once you've created your account, Atlas will give you a Cluster with 500MB for free. One important thing worth noting is whitelisting your connection IP address. If you ignore this step, you won't have access to the cluster. You should see a connect button around the dashboard. Click on that and choose Python. This will give you a connection url. Copy it and save it since we will use this later. We will use that for our app. Go ahead and create a database and call it names_db. In the db, create a collection and call it names_col. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check out Heroku CLI installation by going to &lt;a href="https://devcenter.heroku.com/articles/heroku-cli" rel="noopener noreferrer"&gt;https://devcenter.heroku.com/articles/heroku-cli&lt;/a&gt; and get it installed on your environment&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step 1: Connecting with database using MongoDB Atlas
&lt;/h2&gt;

&lt;p&gt;To start, fire up your terminal and navigate to your backend folder. If you followed the last tutorial, the backend folder will consist of only an app.py file. Open app.py on your IDE and look for the line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mongoClient = MongoClient('mongodb://127.0.0.1:27017')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and change it to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mongoClient = MongoClient('mongodb+srv://&amp;lt;username&amp;gt;:&amp;lt;password&amp;gt;@cluster0-e6reb.mongodb.net/test?retryWrites=true&amp;amp;w=majority')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace username and password with the username and password you have used when creating the database on MongoDB Atlas. After the connection has been established, we are good to start the deployment process. &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Deploying backend
&lt;/h2&gt;

&lt;p&gt;To deploy a Flask application to Heroku, you will need two additional file; Procfile and requirements.txt&lt;/p&gt;

&lt;h4&gt;
  
  
  &amp;gt; FReMP/backend/requirements.txt
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flask
gunicorn
pymongo
flask_cors
dnspython
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The requirements.txt file contains of list of python packages that the application will need before starting.&lt;/p&gt;

&lt;h4&gt;
  
  
  &amp;gt; FReMP/backend/Procfile
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;web: gunicorn app:app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a file and name it Procfile in the backend folder. This is executed right after installing the packages and starts the application.&lt;/p&gt;

&lt;p&gt;Afterwards, we deploy the backend.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git init
$ heroku git:remote -a be-name-app
$ git add .
$ git commit -m 'init'
$ git push heroku master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Testing backend using Postman
&lt;/h2&gt;

&lt;p&gt;You can test if your backend has been deployed successfully using the route /getnames/. At this point, you will receive an empty list of names, but if you can see the image below, that means the backend has been deployed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fv7ai3b4pyxcu48nefkfk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fv7ai3b4pyxcu48nefkfk.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4:  Deploying frontend
&lt;/h2&gt;

&lt;p&gt;Now that our backend has been deployed, let's deploy our front end so that clients can start using the application.&lt;/p&gt;

&lt;p&gt;There are two lines of code that you need to change before continuing. In App.js, we are currently calling localhost. So we need to change that and start calling the API that we just created. We'll make these changes in App.js.&lt;/p&gt;

&lt;h4&gt;
  
  
  &amp;gt; FReMP/frontend/src/App.js
&lt;/h4&gt;

&lt;p&gt;In App.js, look for:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await fetch('/addname/' + this.state.name, {
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and change it to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await fetch('https://be-name-app.herokuapp.com/addname/' + this.state.name, {
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Secondly, look for:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch('/getnames/')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and change it to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch('https://be-name-app.herokuapp.com/getnames/')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it. We are good to go. We can now start the deployment process. To deploy a ReactJS application we need to add the NPM/Yarn and NodeJS version in 'package.json'.&lt;/p&gt;

&lt;h4&gt;
  
  
  &amp;gt; FReMP/frontend/package.json
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  "engines": {
    "yarn": "1.22.4",
    "node": "12.16.0"
  },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After defining the versions, we can deploy using Git.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git init
$ heroku git:remote -a fe-name-app
$ heroku buildpacks:set https://github.com/mars/create-react-app-buildpack.git
$ git add .
$ git commit -m 'init'
$ git push heroku master

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that is it! You can now open browser at &lt;a href="https://fe-name-app.herokuapp.com" rel="noopener noreferrer"&gt;https://fe-name-app.herokuapp.com&lt;/a&gt; to see a live version of the application. If you add a name and submit, it will store the name to mongodb and re render the list of names with the name you just added.&lt;/p&gt;

&lt;p&gt;Cheers (;&lt;/p&gt;

</description>
      <category>flask</category>
      <category>react</category>
      <category>mongodb</category>
      <category>python</category>
    </item>
    <item>
      <title>FReMP Stack (Flask, ReactJS, MongoDB, Python)</title>
      <dc:creator>Hans(Akhil) Maulloo</dc:creator>
      <pubDate>Wed, 01 Jul 2020 09:49:30 +0000</pubDate>
      <link>https://dev.to/kouul/frmp-stack-5g9</link>
      <guid>https://dev.to/kouul/frmp-stack-5g9</guid>
      <description>&lt;p&gt;Technology keeps on evolving everyday and developers constantly look for more and more things to get their hands-on. In this article, I will be introducing a new full stack framework, called &lt;strong&gt;FReMP&lt;/strong&gt;. The abbreviation used is not the best one, but it just gets the work done in justifiable ways.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is FReMP?&lt;/li&gt;
&lt;li&gt;How to install FReMP?&lt;/li&gt;
&lt;li&gt;Building a simple app&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is FReMP?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;FReMP&lt;/strong&gt; stands for &lt;strong&gt;F&lt;/strong&gt;lask, &lt;strong&gt;Re&lt;/strong&gt;actJS, &lt;strong&gt;M&lt;/strong&gt;ongoDB and &lt;strong&gt;P&lt;/strong&gt;ython. Unlike &lt;strong&gt;MEAN&lt;/strong&gt; and &lt;strong&gt;MERN&lt;/strong&gt;, the FReMP stack uses Python to deal with the back end part. Therefore, all core operations such as creating and handling APIs or dealing with functional/OO logic can easily be dealt in Python. As for the front end, it uses Javascript, which allows you to do common operations, such as validating input fields and updating components on the DOM.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to install FReMP?
&lt;/h2&gt;

&lt;p&gt;In this section, we will go through the steps to install the FReMP stack on a Linux environment(Ubuntu).&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Install Flask
&lt;/h3&gt;

&lt;p&gt;To install flask, we need to make sure Python is installed. Since Python is deprecated and Python3 has taken over, we will use Python3 for this tutorial.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ apt-get install python3
$ apt-get install python3-pip
$ sudo -H pip3 install flask
$ flask --version
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;pip&lt;/strong&gt; is a package manager for python, and is used to install Flask globally on your environment using -H flag.&lt;/li&gt;
&lt;li&gt;At the time of this writing, the latest version of Flask is 1.1.1&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Install ReactJS
&lt;/h3&gt;

&lt;p&gt;To install ReactJS, we need to install NodeJS first, then use npm/yarn to install the necessary modules. For this tutorial, we use install and use yarn.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ apt-get install nodejs
$ sudo npm install -g yarn
$ sudo npm install -g npx
$ yarn --version
$ npx --version
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;yarn&lt;/strong&gt; is a package manager for javascript and is much faster and lighter than npm.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;npx&lt;/strong&gt; is used to run the module create-react-app and this will create the starter project for our front end.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Install MongoDB
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ apt-get install mongodb
$ mongo --version
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;To ensure you have everything installed properly, check the version of each framework. If the versions show up without any error, you should be good to go.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building a simple app
&lt;/h2&gt;

&lt;p&gt;In this section, we will build a simple interface that will, locally, allow the user to write his name in a form and on submitting the form, the name is saved in mongodb and at the same time all the names are retrieved and displayed on the user interface. Below is an example of how the final product will look like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YVpKor04--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/yat7tto64alscu3x6usw.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YVpKor04--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/yat7tto64alscu3x6usw.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I did not focus on stylings so much, I tend to make it as minimal as possible for simplicity. So let's get started!&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Project Folder
&lt;/h4&gt;

&lt;p&gt;We will start by making a root folder to contain both the front end and the back end of the application. In this case, we'll call the root folder 'frmp-app'. Feel free to call it whatever you want.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkdir frmp-app
$ cd frmp-app
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Create React frontend folder
&lt;/h4&gt;

&lt;p&gt;Secondly we'll create the front end folder and call it 'frontend'. To do so, run the following command and wait for it to finish:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ create-react-app frontend
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;At this point, your directory should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~/frmp-app$ ls -al
total 16
drwxrwxr-x  4 akhil akhil 4096 zin 30 17:55 .
drwxr-xr-x 13 akhil akhil 4096 zin 30 17:39 ..
drwxrwxr-x  6 akhil akhil 4096 zin 30 17:44 frontend
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After the folder 'frontend' is created, you can 'cd frontend' and start doing changes on the frontend foler. The first change you got to make is to define a proxy in &lt;em&gt;package.json&lt;/em&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  "proxy": "http://localhost:5000"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Add the line to the bottom of package.json. Whenever a request hits goes from localhost:3000, it hits the proxy and is redirected to localhost:5000. The backend processes the request with the information in it and replies back. After setting the proxy, we can implement the HTML form in the App.js component.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;src/App.js&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./App.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Results&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components/Results&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;NewName&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components/NewName&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;names&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
      &lt;span class="na"&gt;loading&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handleChange&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handleChange&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handleSubmit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handleSubmit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;handleChange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;handleSubmit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;loading&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/addname/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;GET&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getNames&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;


  &lt;span class="nx"&gt;getNames&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/getnames/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
          &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;names&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;loading&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
      &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;componentDidMount&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getNames&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;header&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App-header&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;NewName&lt;/span&gt; &lt;span class="nx"&gt;handleChange&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handleChange&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;handleSubmit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handleSubmit&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;          &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loading&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Loading&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&amp;gt; : &amp;lt;Results {...this.state} /&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/header&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;As you may have seen, we have two components namely 'NewName' and 'Results'.&lt;/p&gt;

&lt;p&gt;NewName is the component which contains the input bar. The user writes his name and press Enter.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;src/components/NewName.js&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;NewName&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;form&lt;/span&gt; &lt;span class="nx"&gt;onSubmit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handleSubmit&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;
                        &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                        &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;newName&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                        &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
                        &lt;span class="nx"&gt;onChange&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handleChange&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
                        &lt;span class="nx"&gt;placeholder&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;New Name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                        &lt;span class="nx"&gt;autoFocus&lt;/span&gt;
                        &lt;span class="nx"&gt;autoComplete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;off&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
                    &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;submit&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Add&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;                &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/form&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;NewName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Results is the component that displays the list of names.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;src/components/Results.js&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;Results&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;row&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; 
                &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Results&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now that we are completely done with the frontend section, we can change directory and move to the root directory and create our backend folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd ..
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Create Flask backend folder
&lt;/h4&gt;

&lt;p&gt;After creating our front-end starter project, we will set up our backend by creating a folder called 'backend' and keep all logic and operations related to APIs and database in here. To do so, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkdir backend
$ touch app.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;At this point, your directory should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~/frmp-app$ ls -al
total 16
drwxrwxr-x  4 akhil akhil 4096 zin 30 17:55 .
drwxr-xr-x 13 akhil akhil 4096 zin 30 17:39 ..
drwxrwxr-x  2 akhil akhil 4096 zin 30 18:01 backend
drwxrwxr-x  6 akhil akhil 4096 zin 30 17:44 frontend


&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;app.py&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;flask&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;redirect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url_for&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;pymongo&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;MongoClient&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;flask_cors&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;CORS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cross_origin&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;json&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;cors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;CORS&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'CORS_HEADERS'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'Content-Type'&lt;/span&gt;


&lt;span class="n"&gt;mongoClient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;MongoClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'mongodb://127.0.0.1:27017'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mongoClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_database&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'names_db'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;names_col&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_collection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'names_col'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'/addname/&amp;lt;name&amp;gt;/'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;addname&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;names_col&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;insert_one&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;()})&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;redirect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'getnames'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'/getnames/'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;getnames&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;names_json&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;names_col&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;find&lt;/span&gt;&lt;span class="p"&gt;({}):&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;names_col&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;find&lt;/span&gt;&lt;span class="p"&gt;({}).&lt;/span&gt;&lt;span class="n"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="n"&gt;names_json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="s"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'_id'&lt;/span&gt;&lt;span class="p"&gt;])})&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;names_json&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;"__main__"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;debug&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Since we are connection Python with MongoDB, we will use pymongo and use the MongoClient function to establish the connection. MongoClient accepts a string as parameter, and the string is the url with the port that connects your pc to mongodb, i.e, &lt;em&gt;mongodb://127.0.0.1:27017&lt;/em&gt;. In the cluster, we will create a database called &lt;em&gt;names-db&lt;/em&gt; and inside the database, we will create a collection, &lt;em&gt;names-col&lt;/em&gt;, which will contain a list of json objects. Each object will the name input by the user. After getting the collection name, we define two methods, namely, addname and getnames. When &lt;em&gt;addname&lt;/em&gt; is called, it saves the name passed into the db. Then the second method calls all the names in the db and sends them to the frontend, on the component &lt;em&gt;Results&lt;/em&gt;. &lt;/p&gt;

&lt;h4&gt;
  
  
  4. Mongo shell
&lt;/h4&gt;

&lt;p&gt;This part is optional. If you want to see the names directly in your database, you can fire up the terminal and run mongo, which will open the mongo shell.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mongo
$ use names-db
$ db.names-col.find()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  5. Run the project
&lt;/h4&gt;

&lt;p&gt;To run the project and see you app in action, you will open two terminals. On one terminal, change directory to frontend and on the other terminal, change directory to backend:&lt;/p&gt;

&lt;p&gt;Inside your frontend directory, run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ yarn start
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Inside your backend directory, run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ python3 app.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you followed the instruction clearly so far, this should run flawlessly.&lt;/p&gt;

&lt;p&gt;Open up localhost:3000 on your browser to get the application live. &lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>flask</category>
      <category>react</category>
      <category>mongodb</category>
      <category>python</category>
    </item>
    <item>
      <title>How was DockerCon 2020</title>
      <dc:creator>Hans(Akhil) Maulloo</dc:creator>
      <pubDate>Fri, 29 May 2020 06:12:56 +0000</pubDate>
      <link>https://dev.to/kouul/how-was-dockercon-2020-mm2</link>
      <guid>https://dev.to/kouul/how-was-dockercon-2020-mm2</guid>
      <description>&lt;p&gt;Hello dev people,&lt;/p&gt;

&lt;p&gt;Dockercon 2020 was truly a huge success to me, with a great team and a well organized plan behind the scene. I assume that the organisation was not very easy, but the team nailed it. Since this year's dockercon was made online, all I had to do to attend was to register and that's it. It was fairly easy for me to switch between the different talks from time to time. I imagine it would have been a costly task for me to join this conference physically, but since it was made virtual, I could easily join it and give my personal opinions on how it all went.&lt;/p&gt;

&lt;p&gt;The fact that all these developers and docker captains, from different regions of the globe, were sharing their knowledge about particular topics in the docker world, is truly fascinating to me.&lt;/p&gt;

&lt;p&gt;Some of the talks that really intrigued me:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docker.events.cube365.net/docker/dockercon/content/Videos/hgMFTyX5kYKmTPWZo"&gt;How to get started with Docker&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docker.events.cube365.net/docker/dockercon/content/Videos/eWWPtj5dmHAmoYypc"&gt;Best Practices for Compose-managed Python Applications&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docker.events.cube365.net/docker/dockercon/content/Videos/oTctQReJCRWkfXfMy"&gt;Securing Your Containerized Applications with NGINX&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docker.events.cube365.net/docker/dockercon/content/Videos/kmhESLz8DvkkpgEqs"&gt;You Want To Kubernetes? You MUST Know Docker!&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docker.events.cube365.net/docker/dockercon/content/Videos/wLMYLQAYj7mvHrvZe"&gt;Delivering Desktop Apps in Containers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docker.events.cube365.net/docker/dockercon/content/Videos/GZpzJAapdrSXohzNz"&gt;Your Container has Vulnerabilities. Now What?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docker.events.cube365.net/docker/dockercon/content/Videos/wHjxizoWgFgCYu6aF"&gt;Hardening Docker daemon with Rootless Mode&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Although I could not attend the conference till the end, I will make it a must to watch all talks on YouTube sooner or later. Personally, I think there should be more conferences like this one since it gives people the opportunity to start coding and for those who already code, it gives them the chance of getting hands dirty with live DEVs sessions and at the same time, learn the best practices of their technology. We all know how documentation can become tedious at some point, but watching a conference can wipe out the tedious part of it.&lt;/p&gt;

&lt;p&gt;I was, simultaneously, following the hashtags on social media platforms and I can say that there was a really big crowd of developers watching &lt;br&gt;
the conference.&lt;/p&gt;

&lt;p&gt;Some of the hashtags you can check out:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#dockercon
#dockerconjobs
#dockerselfie
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Having said all this, let me point out that these were all opinions from my point of view on DockerCon 2020.&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>docker</category>
      <category>dockercon</category>
      <category>dockerconjobs</category>
    </item>
    <item>
      <title>Rendering HTML in Flask</title>
      <dc:creator>Hans(Akhil) Maulloo</dc:creator>
      <pubDate>Sat, 23 May 2020 15:55:31 +0000</pubDate>
      <link>https://dev.to/kouul/rendering-html-in-flask-3i35</link>
      <guid>https://dev.to/kouul/rendering-html-in-flask-3i35</guid>
      <description>&lt;p&gt;Hello World!&lt;br&gt;
In my &lt;a href="https://dev.to/kouul/building-a-minimal-flask-application-290"&gt;previous article&lt;/a&gt;, I talked about building the most simple application you can ever build using Flask. In this article, I will write about rendering HTML files instead of return static strings. It will not really matter if you did not read the previous article, because I will build a new application from scratch that renders HTML pages in this article.&lt;/p&gt;
&lt;h4&gt;
  
  
  Content
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Prerequisites&lt;/li&gt;
&lt;li&gt;Generate HTML pages&lt;/li&gt;
&lt;li&gt;Build flask application&lt;/li&gt;
&lt;li&gt;Run the app!&lt;/li&gt;
&lt;/ol&gt;


&lt;h3&gt;
  
  
  1. Prerequisites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Python3&lt;/li&gt;
&lt;li&gt;Pip3&lt;/li&gt;
&lt;li&gt;Flask&lt;/li&gt;
&lt;li&gt;Basics of Html&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Directory layout&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.
├── app.py
├── templates/
    └── index.html
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Before starting, please create a directory as shown above. This will be where we will store all our code.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Generate HTML pages
&lt;/h3&gt;

&lt;p&gt;In flask, we use a &lt;em&gt;render_template&lt;/em&gt; method to render any HTML page on our browser. This method will, first of all, look for a specific folder in the project's root folder called &lt;em&gt;templates&lt;/em&gt;. All your html pages need to be placed in &lt;em&gt;templates&lt;/em&gt; so that it can rendered correctly on your browser. Below is a snippet for a simple Hello World which I will write to templates/index.html.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- templates/index.html --&amp;gt;&lt;/span&gt;
&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Hello World&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello World!!&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Build flask application
&lt;/h3&gt;

&lt;p&gt;After writing our rendering template, we have to pass this to our backend code for it to know when to return it to the browser. This page can be rendered when the user go to route '/' or '/test'. We need to specify this in our back-end code. Below you will find the snippet for our &lt;em&gt;app.py&lt;/em&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def hello():
  return render_template('index.html')

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

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Compared to &lt;a href="https://dev.to/kouul/building-a-minimal-flask-application-290"&gt;previous article&lt;/a&gt;, we are importing a render_template method from flask and we are using this method to return our &lt;em&gt;index.html&lt;/em&gt; file that we created earlier.&lt;/p&gt;

&lt;p&gt;After you set this, you are good to go and run the application.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Run the app!
&lt;/h3&gt;

&lt;p&gt;To run the app, simply run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python3 app.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After that, open up localhost:5000 to see you newly written HTML page.&lt;/p&gt;




&lt;p&gt;Thank you for reading and I hope this article was helpful. I will be seeing you in my next article.&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>python3</category>
      <category>flask</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Building a Minimal Flask Application from scratch</title>
      <dc:creator>Hans(Akhil) Maulloo</dc:creator>
      <pubDate>Thu, 30 Apr 2020 06:51:12 +0000</pubDate>
      <link>https://dev.to/kouul/building-a-minimal-flask-application-290</link>
      <guid>https://dev.to/kouul/building-a-minimal-flask-application-290</guid>
      <description>&lt;p&gt;Hello world!&lt;br&gt;
In this article, I will be demonstrating how Flask is used in web development by building the most basic application you can ever build; which is displaying the message 'Hello World!' on your browser. &lt;/p&gt;
&lt;h4&gt;
  
  
  Content
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Introduction to Flask&lt;/li&gt;
&lt;li&gt;Prerequisites&lt;/li&gt;
&lt;li&gt;Install Flask&lt;/li&gt;
&lt;li&gt;Build flask application&lt;/li&gt;
&lt;li&gt;Run the app!&lt;/li&gt;
&lt;/ol&gt;


&lt;h3&gt;
  
  
  1. Introduction to Flask
&lt;/h3&gt;

&lt;p&gt;Flask, known as Python's micro web framework, has gained a lot of popularity over the past recent years. It is used for development of web application and, personally, I believe it provides all the flexibility needed to build a powerful full stack web application.&lt;/p&gt;

&lt;p&gt;While Flask is mostly used for the backend, it deals with frontend with a templating language called Jinja2 with which you can write HTML pages from scratch and render on your browser.&lt;/p&gt;
&lt;h3&gt;
  
  
  2. Prerequisites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Python3&lt;/li&gt;
&lt;li&gt;Pip3&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As some of you may know, Python has come to an end of life on December 2019, and Python3 is now taking over. All os are coming with Python3 installed by default. And since we are using Python3, we will obviously need to install pip3. It may come by default on certain OS.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Install Flask
&lt;/h3&gt;

&lt;p&gt;First things first, you have to make sure that you have Flask installed on your machine. We will use pip, a package manager that allows you to install and uninstall python modules easily, to install Flask on our environment.&lt;br&gt;
&lt;/p&gt;

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



&lt;p&gt;To ensure Flask has been installed correctly, you can run the following command, which will display the version of Python and Flask you currently have on your machine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ flask --version
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you can see the versions correctly, that means Flask is installed. You are good to go! Now that we have setup our environment, let's get to coding!&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Build flask application
&lt;/h3&gt;

&lt;p&gt;You can create an empty directory and call it whatever you want to name your application. Inside the directory create an &lt;strong&gt;&lt;em&gt;app.py&lt;/em&gt;&lt;/strong&gt;. This python script will contain you minimal Flask application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# app.py
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;flask&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Flask&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;index&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;'&amp;lt;h1&amp;gt;Helllo World!&amp;lt;/h1&amp;gt;'&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;'__main__'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This is everything you need to run a minimal Flask application on your machine! Pretty cool right? &lt;/p&gt;

&lt;p&gt;Let's dive into app.py and examine each line to see what it does.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;First we imported the Flask class.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Using the Flask class we imported, we create an instance and pass the name of our application as the first argument. Here we are passing __name__.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;__name__ is a special built-in character in Python.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We then use something called the route decorator to specify the route we want to create in our application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;After the route '/' is hit, it should execute a method. This method is defined right below the route decorator&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This where you specify the actions you want the app to do when the user call the predefined route('/').&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Last but not least, we call our app, which we defined on line 2, with app.run().&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5. Run the app!
&lt;/h3&gt;

&lt;p&gt;Now we have everything setup, we only need to run the script to get our message on the browser. Open up a terminal, change directory to your project's root directory and simply run the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ python3 app.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Open up localhost:5000 on your browser and your message should be there waiting for you! :)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YY9tb_Ec--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7bwdr8fbbbinp9udzglc.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YY9tb_Ec--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7bwdr8fbbbinp9udzglc.jpeg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you have enjoyed it so far, feel free to checkout &lt;a href="https://buildflaskapp.kouul.website"&gt;buildflaskapp&lt;/a&gt;, which is a command-line tool to automatically generate a minimal Flask application by running one command.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;Congrats if you made it up to here! You now have a minimal Flask application which you can modify and add in your own content. Some of the next articles regarding Flask will include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rendering html page with Flask&lt;/li&gt;
&lt;li&gt;Building a CRUD application with Flask&lt;/li&gt;
&lt;li&gt;Create a REST api with Flask &lt;/li&gt;
&lt;li&gt;Containerizing our flask application&lt;/li&gt;
&lt;li&gt;Deploying flask apps on heroku&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>python3</category>
      <category>flask</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Build a Flask web app by running one command!</title>
      <dc:creator>Hans(Akhil) Maulloo</dc:creator>
      <pubDate>Wed, 29 Apr 2020 17:12:03 +0000</pubDate>
      <link>https://dev.to/kouul/build-flask-app-240o</link>
      <guid>https://dev.to/kouul/build-flask-app-240o</guid>
      <description>&lt;h2&gt;
  
  
  About &lt;em&gt;buildflaskapp&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;buildflaskapp&lt;/em&gt; is a command-line tool whose aim is to generate a minimal Flask application by simply running a command from your CLI.&lt;/p&gt;

&lt;h3&gt;
  
  
  Demo
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sYcthadf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/616smu6linhexstcc0xu.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sYcthadf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/616smu6linhexstcc0xu.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It has been tested on Linux and Window terminal interface and it should work without any problem. If you happen to encounter any kind of issue, please feel free to &lt;a href="https://github.com/askyourkode/buildflaskapp/issues/new"&gt;raise an issue&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pip3 install buildflaskapp
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Official website
&lt;/h3&gt;

&lt;p&gt;You can check out the &lt;a href="https://buildflaskapp.kouul.website"&gt;official website&lt;/a&gt; to learn more about how to use the tool.&lt;/p&gt;

&lt;h3&gt;
  
  
  Source code
&lt;/h3&gt;

&lt;p&gt;The code is freely available &lt;a href="https://github.com/askyourkode/buildflaskapp"&gt;on Github&lt;/a&gt; with an MIT license. Feel free to create issues or even pr if you think a new feature should be added.&lt;/p&gt;

&lt;h2&gt;
  
  
  Additional Resources/Info
&lt;/h2&gt;

&lt;p&gt;At the time of this writing, &lt;em&gt;buildflaskapp&lt;/em&gt; supports few options that you can pass in when building the app; options such as adding bootstrap cdn, jQuery cdn and font-awesome cdn automatically.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://pypi.org/project/buildflaskapp/"&gt;PyPi&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/askyourkode/buildflaskapp/"&gt;Github&lt;/a&gt;&lt;br&gt;
&lt;a href="https://buildflaskapp.kouul.website/"&gt;Official Website&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5w90UkCx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zaxmxr50prvjp51lpyml.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5w90UkCx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zaxmxr50prvjp51lpyml.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python3</category>
      <category>pip3</category>
      <category>flask</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
