Flask Installation and Setup

Posted By : Aakash Vishwakarma | 29-Jul-2022

Written in python language, Flask is a web framework that provides libraries to create lightweight web applications in python. It is developed by Armin Ronacher.

 

Flask Environment Setup

We should have python 2.7 or higher installed in order to install flask on the system. However, we recommend utilizing python 3 for the development in the flask.

Install virtual environment (virtualenv)

virtualenv is considered the virtual python environment builder which is leveraged to construct multiple python virtual environments side by side. It can be installed by using the following command.

$ pip install virtualenv

Once it is installed, we can build the new virtual environment into a folder as given below.

$ mkdir flask_project

$ cd flask_project

$ virtualenv venv

To activate the corresponding environment, use the following command on the Linux operating system.

$ source venv/bin/activate

We can now install the flask by using the following command.

$ pip install flask


After Flask installation go inside your flask project

$ cd flask_project

 

And now  create a html file login.html.

<html>

   <body>

      <form action = "http://localhost:5000/login" method = "post">

         <table>

            <tr>

               <td>Name</td>

               <td><input type ="text" name ="User NAme"></td>

            </tr>

            <tr>

               <td>Password</td>

               <td><input type ="password" name ="Password"></td>

            </tr>

            <tr>

               <td><input type = "submit"></td>

            </tr>

         </table>

      </form>

   </body>

</html>

Create python file login.py


 

from flask import *

app = Flask(__name__)

@app.route('/login',methods = ['POST'])

def login():

   username=request.form['uname']

   passwrd=request.form['pass']

   if uname=="aakash" and passwrd=="Akky@123":

      return f"Welcome {username}"

   return "Something Went Wrong"

if __name__ == '__main__':

   app.run(port=5000,debug = True)

 

now goto terminal and run login.py file

$python login.py

Then goto chrome and run login.html file and enter User name and Password and click on submit button it will redirect to the next page where you will get a message- Welcome <your name>


 

Related Tags

About Author

Author Image
Aakash Vishwakarma

Aakash Vishwakarma is a highly skilled backend developer with years of industry experience. He has a comprehensive understanding of the latest technologies and practical experience working with tools and frameworks like Python Django, Django Rest Framework, Odoo14, Odoo15, HTML, CSS, JavaScript, and Jquery, as well as databases. He has contributed to the successful delivery of various client projects, including Pando Mall, Hatrik Marketplace, My Mandi, File Comparison, and TRO Projects. Aakash has a creative mindset and strong analytical skills that enable him to think critically and explore new technologies with ease, making him an asset to any project

Request for Proposal

Name is required

Comment is required

Sending message..