Project Title: Profile Application using Python Flask and MySQL
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. Side tabs are used for single page web applications or to display different contents.
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 geekprofile with the table accounts.
Step-5: Execute the query.
(3) Creating Project
Step-1: Create an empty folder ‘geeksprofile’.
Step-2: Now open your code editor and open this ‘geeksprofile’ folder.
Step-3: Create ‘app.py’ folder and write the code given below.
Step-4: Create the folder ‘templates’. create the files ‘index.html’, ‘display.html’, ‘update.html’, ‘login.html’, ‘register.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 nine fields i.e. username, password, email, organisation, address, city, state, country, postal code. 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. When user logs in successfully, this page is displayed and ‘Logged in successful!’ is displayed.
Step-8: Open ‘display.html’ file and write the code given below. Here, the user information stored in database are displayed.
Step-9: Open ‘update.html’ file and write the code given below. The user can update his/her data which also updates the database.
Step-10: Create the folder ‘static’. create the file ‘style.css’ inside the ‘static’ folder and paste the given CSS code.
Step-11: 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.
Step-4: You can view your profile details in display page and also you can update your details in update page.
If login is successful, Index Page:
Before updation, Display page:
After updation, Display page:
Database – Before update:
Database – After update:
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.
- Login and Registration Project Using Flask and MySQL
- Flask - (Creating first simple application)
- 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
- Setup API for GeeksforGeeks user data using WebScraping and Flask
- 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
- Build an Application to Search Installed Application using Python
- Deploy Python Flask App on Heroku
- Subdomain in Flask | Python
- Connect MySQL database using MySQL-Connector Python
- Dockerize your Flask App
- Deploying a TensorFlow 2.1 CNN model on the web with Flask
- Setting up Google Cloud SQL with Flask
- Template Inheritance in Flask
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.