0% found this document useful (0 votes)
7 views9 pages

Django Framework

The document provides an overview of the Django framework, highlighting its purpose for creating database-driven websites using Python, its architecture based on the MVT design pattern, and key features such as ORM for database interactions and CRUD operations. It outlines the project execution flow, including URL handling, view mapping, and template rendering, along with instructions for setting up a Django project and app. Additionally, it includes practical examples of creating models, views, and templates for an employee management system.

Uploaded by

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

Django Framework

The document provides an overview of the Django framework, highlighting its purpose for creating database-driven websites using Python, its architecture based on the MVT design pattern, and key features such as ORM for database interactions and CRUD operations. It outlines the project execution flow, including URL handling, view mapping, and template rendering, along with instructions for setting up a Django project and app. Additionally, it includes practical examples of creating models, views, and templates for an employee management system.

Uploaded by

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

Django Framework

Purpose:To create websites or apply using python

 Django-Server Side Backened Web Framework.


 Default Port no-8000 :it represents application.
 0 to 65,536 ports can be used.
 Localhost address also know as home address(127.0.0.1)
 It is used to develop database driven websites.
 It provides website and default data base known SQLite
 Drivers or connectors.
 It follows a Design Patterns.MVT(Model View Template) is used in Django
 Design Patterns: It is the repeates solution for commonly occurring
problems in Software.(mainly 23 patterns are available).
 MODEL-it represents data usually from database.Django delivers data in
to user or website or end user or system using ORM(object relational
mapping).( model -class)
 All the models should be located in file named as models.py.
 ORM-it makes database connectivity easier and interactions with the DB
easier i.e is CRUD.It helps in the automatic table creation.and complex
SQL Quires. It directly converts class into relation in a DB.(obj -rows and
instances-columns).
 ORM converts into sql statements using SAVE().
 View-Request handler. In python terms it is a method or function which
takes http request as arguments/parameters.
 All the views are located in a file named views.py.
 Template-text file or .html file which contains of standard html code to
describe the layout of webpage(html) along with some actual logic to
display (Django tags ).
 Notes-All templates (html files) should be in Template Folder.
 Django uses tool called Django ORM.
 Flask-SQLALchemey ORM
 Java-Hibervate ORM
 Features of Django:
1. open source.
2. dynamic web applications.
3. it emphasises on concept known as “DRY”
don’t repeat yourself.
4. login system/authentication & authorization.
Authentication-allow users on credentials.
Authorization-upto which extension one can
use resources.
5. database connectivity.
6. it provides crud operations.(create ,read
update and delete)

URLS:
-UNIFORM RESORCE LOCATER.
PURPOSE:To navigate the website.All urls are available in url.py

Django Project Execution:

1.AFTER END USER HIT THE URL ENTER THEN IT CHANGES TO HTTP
REQUEST AND CHECKS IF IT IS IN URL.PY

2. THEN IT MAPS WITH VIEW.PY

3.IF IT THE URL IS PRESENT, then models get imported and other
Django modules as arguments. IF not there 404 errors occurs.

4.These are imported by Templates .

5.templates display result as http response.

Make isolation among projects.

Create venv

Py -m venv soc-3

Py-python launcher -m venv-venv model soc-3 -name of env

The statement to create a project


django-admin startproject cse_cst_club
command to run server- py manage .py runserver (django web
server)
day-1
creating a web app named as :py manager.py startapp students
then in user student view.py

 to delete env is rmdir /s /q soc-3


1)create an app student
2)create a view to display svec with new url pattern svec/
3)render html file for displaying the course list using urls pattern
courses.
Migration:python manage.py makemigrations students)
Then python manage.py migrate
4)render a courses list with proper heading and list of courses
(undordered list)with url pattern courses.
5)create a model named as Student with two fields first name and
last name in a file called models.py
(student extends models.model.py)
Py manage.py makemigrations studenst
Py manage.py sqlmigrate students 001
To open shell: python manage.py shell
>> from students.models import Student
(not errosr imported crtly)
To create 5 obj ,make them as a list and repeat a loop to save it and
display it
List=[s1,s2,s3,s4,s5]
Students_list=[s1,1]
For x in students_list:
x.save()
Student.objects.all().values()
Get 4 obj firstname and lastnae
Del 4 ob
Retrieving the 4 th obj
S1=Student.objects.all()[index]
Query set:
Update the model
Student by adding phone no,and joined_date
X=phone=55324
x.joined_date=’2323-33-44’
x.save()
django tags start with curly braces.
Double curly braces-getting some value of variables in a html code
{%for loop%}-control structures,loops.
*)display the data of Student table by preparing a template
Display the records of a table in an unordered list.
Render is a overloaded method
Context is dictionary type and request is http

List of dictionaries
127.0.0.1:8000/admin/
Py manage.py createsuperuser

Bootstrap-Prototype to production
Project-employee management system
Without specifying url-index page

View all employees add an employee remove an em filter employee


detaisl
Employee -model
First page-index.html
Whaterver enduser submits ,these details should be controlled by
view(backened-python) to form obj and saved
By adding id ,empolu has to be deleted (remobe based on id)

View-all_emp
View-add_emp
View-remove an employee
View-filter employee detailds
Create a project under soc3 environment,the project name is
emp_mgt and create an app under this project emp_app ,add
emp_app settings.py .now create template folder under emp_app
Create 5 html files
1.index.html
2.
2.add_emp.html
3.remove_emp.html
4.view_all_emp.html
5.filter_emp.html

Now create urls.py file under emp_app ,include emp_app.urls in urls


of emp_mgt
Now open index.html file ,then create view named as index
Then it is view and them mapped with url

def index(request):
return render(request,’index.html’)
then open urls.py file
path(‘ ’, views.index,name=”index”)

create 3 models in models.py file


Django models documentations
1.Department-fileds are-name,location,
2.Roll-field-name (all are charfield)
3.Employee-Firstname ,Lastname,bonus (integerfiled),salary
(int),phone(int),hire_date(datefiled)
Dept=models.foreignkey(dept,on_delete=cascade))
Roll=models.foreignkey(roll,on_delete=cacase))

Write str func in model to display the embed


Then migrate
Create super user and login with admin
Register all 3 models in admin.py

From .models import depart,roll,emp


Admin.site.emp ,admin.site.roll…
Fill detaisl roll ,dep ,emp in admin page

Add an employee
First and last text then remain number
F ,l,s,d,r,b,phone
Form action url name
If request.method==’post’:
F=request.POST[‘’]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy