Project Title: Login and registration Project using Flask framework and MySQL Workbench.
Type of Application (Category): Web application.
Introduction: A framework is a code library that makes a developer’s life easier when building web applications by providing reusable code for common operations. There are a number of frameworks for Python, including Flask, Tornado, Pyramid, and Django. Flask is a lightweight web application framework. It is classified as a micro-framework because it does not require particular tools or libraries.
Pre-requisite: Knowledge of Python, MySQL Workbench and basics of Flask Framework. Python and MySQL Workbench should be installed in the system. Visual studio code or Spyder or any code editor to work on the application.
Technologies used in the project: Flask framework, MySQL Workbench.
Implementation of the Project:
(1) Creating Environment
Step-1: Create an environment. Create a project folder and a venv folder within.
py -3 -m venv venv
Step-2: Activate the environment.
Step-3: Install Flask.
pip install Flask
(2) MySQL Workbench
Step-2: Install ‘mysqlbd’ module in your venv.
pip install flask-mysqldb
Step-3: Open MySQL workbench.
Step-4: Write the following code. The above SQL statement will create our database geeklogin with the table accounts.
Step-5: Execute the query.
(3) Creating Project
Step-1: Create an empty folder ‘login’.
Step-2: Now open your code editor and open this ‘login’ folder.
Step-3: Create ‘app.py’ folder and write the code given below.
Step-4: Create the folder ‘templates’. create the file ‘login.html’, ‘register.html’, ‘index.html’ inside the ‘templates’ folder.
Step-5: Open ‘login.html’ file and write the code given below. In ‘login.html’, we have two fields i.e. username and password. When user enters correct username and password, it will route you to index page otherwise ‘Incorrect username/password’ is displayed.
Step-6: Open ‘register.html’ file and write the code given below. In ‘register.html’, we have three fields i.e. username, password and email. When user enters all the information, it stored the data in the database and ‘Registration successful’ is displayed.
Step-7: Open ‘index.html’ file and write the code given below. This page is displayed when login is successful and username is also displayed. The logout functionality is also included in this page. When user logs out, it moves to fresh login page again.
Step-8: Create the folder ‘static’. create the file ‘style.css’ inside the ‘static’ folder and paste the given CSS code.
Step-9: The project structure will look like this.
(4) Run the Project
Step-1: Run the server.
Step-2: Browse the URL ‘localhost:5000’.
Step-3: The output web page will be displayed.
(5) Testing of the Application
Step-1: If you are new user, go to sign up page and fill the details.
Step-2: After registration, go to login page. Enter your username and password and sign in.
Step-3: If your login is successful, you will be moved to index page and your name will be displayed.
If registration successful:
Before registration, Database table:
After registration, Database table:
If login successful, Indexpage is displayed:
If Login fails:
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Profile Application using Python Flask and MySQL
- Create MySQL Database Login Page in Python using Tkinter
- Python | Simple registration form using Tkinter
- Image Registration using OpenCV | Python
- How to get client_id and client_secret for Python Reddit API registration ?
- Setup API for GeeksforGeeks user data using WebScraping and Flask
- Python | Using for loop in Flask
- Python | Introduction to Web development using Flask
- Python | Build a REST API using Flask
- Create a Weather app using Flask | Python
- Todo list app using Flask | Python
- Deploy Machine Learning Model using Flask
- Sending Emails Using API in Flask-Mail
- Using JWT for user authentication in Flask
- Retrieving HTML From data using Flask
- Connect MySQL database using MySQL-Connector Python
- Login Application and Validating info using Kivy GUI and Pandas in Python
- Flask - (Creating first simple application)
- Deploy Python Flask App on Heroku
- Subdomain in Flask | Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.