Here I explain how to create Python Login page using Flask with MySQL database. Actually this is very easiest script however beginners are initially looking for login form to learn about particular programming. That’s why here we are creating simple login form and data stored into MySQL database with validation.
Moreover this task assigned by lot of interviewers who are looking for job in Python programming language. So they are initially test your knowledge to assign the task of simple login form with database connectivity. In this example we are using Flask web framework for implement the new login form.
But some of interviewers are assigned the task using Django framework or Tkinter. So just carefully listen the questions and then starts to copy and paste the code into your system. If they are not mentioned any framework then you can start with flask with MySQL database. In the previous article we are create login & registration (Signup) form using Django framework with SQLite database.
How to Start ? – Requirements
The initial step is download the python on your machine and here I am using 3.7.2 version. During the installation, you have to check the box for “Add Python to Path” for complete setup. Hereafter only you can able to execute python code, if you are missing to add path then have to manually adding the URL on environment path list. Current Python version is 3.11.1 you can download the latest version for upgrade the bugs.
Second step is Install MySQL Community server and MySQL workbench for communicate with flask to real time database management system.
Suppose already if your system has Python & MySQL database then just ignore above two steps, so once check on your end.
Modules – Python Login Page
- Form Design
- For the sample purpose initially you have to design homepage and navigate the link for Login Form.
- Create template with Flask & Python
- Set validation for both of User Name (Email) and Password
- Session is mandatory to pass the information of welcome page so don’t forget.
- MySQL Queries
- Helps to communicate with database side for store and retrieve user’s information.
- Which is used for navigate the pages from one page to another one.
1. Create Environment
I explain both of Windows, Linux & MAC, so choose your code based on operating system. Maximum of software developers are now starts to use Ubuntu because it’s very good performance when compared to Windows OS.
Windows: cd Login-System-with-Python-Flask-and-MySQL py -3 -m venv venv Linux & MAC cd Login-System-with-Python-Flask-and-MySQL python3 -m venv venv
2. Activate Environment
After that just activate an environment to proceed the further steps. If you are beginner and not able to understand these things ? Don’t worry just watch one video or read official documentation after that you get clear idea about this steps.
Windows venv\Scripts\activate MAC/Linux venv/bin/activate or source venv/bin/activate
3. Install Requirements
It’s same of all Operating system, so you can use below commands to install the particular requirements for execute the project on your machine without any errors.
pip install -r requirements.txt
4. Run Project
Finally it’s time to execute your login form python project. For that just use below code,
Windows set FLASK_APP=main flask run MAC/Linux chmod 777 run ./run
Output/Screenshot – Python Login Page
After run the application, you are getting following screenshot on your system. Alternatively you get any error message just try to sort out with help of stackoverflow, otherwise comment below we are try to solve your bugs.
Source Code – Python Login Page
Above all contents are surely helps to create simple login form with proper validation. Flask is one of the best framework for develop application. So you can start your career with help of Python developer community which is available on open source.