Flask CRUD Application with SQLAlchemy

In this article we are going to learn Flask CRUD Application with SQLAlchemy, we are going to build web application that you can create employee, read employee data from mysql database, update employee data and also delete employee. also we are using SQLAlchemy for this tutorial, if your interested in the video for this course you can check below.

 

 

 

Python Web Development Tutorials

1: Flask Web Development Tutorials

2: Django Web Development Tutorials 

 

 

 

Also you can read more articles on Python GUI Development

1: TKinter GUI Development Tutorials

2: Pyside2 GUI Development Tutorials

3: wxPython GUI Development Tutorials

4: Kivy GUI Development Tutorials 

 

 

 

What is Flask ?

Flask is a web framework. This means flask provides you with tools, libraries and technologies that allow you to build a web application. This web application can be some web pages, a blog, a wiki or go as big as a web-based calendar application or a commercial website.

Flask is part of the categories of the micro-framework. Micro-framework are normally framework with little to no dependencies to external libraries. This has pros and cons. Pros would be that the framework is light, there are little dependency to update and watch for security bugs, cons is that some time you will have to do more work by yourself or increase yourself the list of dependencies by adding plugins.

 

 

 

What is SQLAlchemy ?

SQLAlchemy is the Python SQL toolkit and Object Relational Mapper that gives application developers the full power and flexibility of SQL.

It provides a full suite of well known enterprise-level persistence patterns, designed for efficient and high-performing database access, adapted into a simple and Pythonic domain language.

 

 

What is Flask-SQLAlchemy ?

Flask-SQLAlchemy is an extension for Flask that adds support for SQLAlchemy to your application. It aims to simplify using SQLAlchemy with Flask by providing useful defaults and extra helpers that make it easier to accomplish common tasks.

See the SQLAlchemy documentation to learn how to work with the ORM in depth. The following documentation is a brief overview of the most common tasks, as well as the features specific to Flask-SQLAlchemy.

 

 

 

 

Also you can watch the complete video for Flask CRUD Application with SQLAlchemy

 

 

 

 

 

Installation

For this article first you need to install flask, and after that you need to install flask-sqlalchemy.

 

 

 

 

OK after the installation first you need to create a database, iam using Wamp Server for this tutorial and my database name is crud. after that you need to open your Pycharm IDE and create two folders one for your static files and the second for your templates, in the video i have used bootstrap and jquery static files, but in here i have changed that to BootstrapCDNin your templates you need to create some html files.

 

Flask CRUD Project Structure
Flask CRUD Project Structure

 

 

 

So you can see i have static folder, but because iam using BootstrapCDN, iam not going to add bootstrap and jquery files in their. in the templates folder i have the HTML files that i need for this tutorial.

 

 

 

Let’s add our codes in our app.py.

 

 

 

 

In this code we have created our Mysql Database  configuration. you can see that our database

name is crud.

 

 

 

 

And this is our database model. 

 

 

 

This is our base.html.

 

templates/base.html

 

 

 

 

In here we have created our header.html.

 

templates/header.html

 

 

 

 

And this is our index.html.

 

templates/index.html

 

 

 

 

 

So now run the complete project and this will be the result.

Flask CRUD Application with SQLAlchemy
Flask CRUD Application with SQLAlchemy

Subscribe and Get Free Video Courses & Articles in your Email

 

Share via
Copy link
Powered by Social Snap
×