0% found this document useful (0 votes)
26 views

Web Framework

django basics

Uploaded by

purswanijiten11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Web Framework

django basics

Uploaded by

purswanijiten11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Web Framework

Introduction
● Django is a back-end server side web framework.
● It is free, open source and written in Python.
● It makes it easier to build web pages using Python.
● It is especially helpful for database driven websites.
MVT Pattern- How does Django works?
MVT (Model-View-Template) determines the total structure and
workflow of a Django application. In an MVT architecture —
● The Model manages the data and is represented by a database. A
model is basically a database table.
● The View receives HTTP requests and sends HTTP responses. A
view interacts with a model and template to complete a response.
● The Template is basically the front-end layer and the dynamic
HTML component of a Django application.
Django MVT Pattern
Features
○ Rapid Development
○ Secure
○ Scalable
○ Fully loaded
○ Versatile
○ Open Source
○ Vast and Supported Community
Installation Steps
Installation Steps
Steps for creating a CRUD app in Django
● Install Django & start a new project
● Create an App
● Create the Model
● Create the Admin Interface
● Create the View
● Define the URLs (i.e. URL to View mapping)
● Create the Templates
Installation Steps
Installation Steps

Pip freeze command


shows all packages
installed with Django
Create Django project
The django-admin is Django’s
command-line utility for
administrative tasks. This document
outlines all it can do.
The django-admin script should be on
your system path if you installed
Django via pip. If it’s not in your path,
ensure you have your virtual
environment activated.
Create Django project

This command creates the


django project as ves
manage.py is
automatically created
and set up each
Django project. It does
the same thing as
django-admin but also
sets the
DJANGO_SETTINGS_M
ODULE environment
variable
Create Django project

To stop the server press ctrl c and enter. Once server is stop it will not show you your project
Create Django project
To change the port we can use
runserver and port number
which you want to create ( if you
are doing multiple projects)
CRUD Operations
CRUD stands for Create, Read, Update & Delete. These are the four basic
operations which are executed on Database Models.
1. Read Operation
The ability of the application to read data from the database.
2. Create Operation
The ability of the application to store data in the database.
3. Update Operation
The ability of the application to edit the stored value in the database.
4. Delete Operation
The ability of the application to delete the value in the database.
Example:
Majority of applications on the internet are CRUD applications.
For example –
Facebook uses CRUD operations to save your data on their database.
You can change your profile picture that means perform the update
operation.
Of course, you can see the data in-app or browser which is read
operation.
Also, you can delete your Facebook account which is delete operation.
Summarising it, almost all the applications you use are CRUD
applications.
Implementation steps
Step 1: Django Project Setup

Step 2: Basic Configurations

Step 3: Create View and URL’s for Listing, Create, Read, Update
and Delete Objects

Step 4: Create HTML UI for Ajax

Step 5: Run Migrations and Test your Application


The first thing we need
to do is to create a
model for our items
like— name, quantity,
status, and date. Let’s
create the Item model
class in the
bag/models.py file:
The first thing we need
to do is to add a new
item to our bag.

Let’s create a view


function to add a new
item in bag/views.py
file:
Create View and URL’s for Listing, Create, Read, Update and
Delete Objects
To communicate with view, create bag/urls.py file:
Now let us make the required changes in the HTML form in the
add.html file:
bag/views.py file:
Run Migrations and Test your Application

After migrations, you need to run your Django application,


using below command
https://studygyaan.com/django/how-to-execute-
crud-using-django-ajax-and-json

You might also like