Page 1
Django Based Web Application
Part - II CBSE Syllabus Based
Class -12
By- Neha Tyagi PGT CS KV 5 Jaipur II Shift Blog- www.pythontrends.wordpress.com YouTube Channel : “Python Trends” E-mail: [email protected] Neha Tyagi, KV 5 Jaipur II Shift
CHAPTER -15 CS CHAPTER-9 IP
Page 2
What we learnt in Part-I?
Neha Tyagi, KV 5 Jaipur II Shift
• First we will take a review of what we learnt in first part.
• We learnt creation of Project and app.
• Registering App in to Project.
• Generate webpages in Templates and add an entry in views.py.
• Setting path in url.py.
• Running Django server.
• Opening of pages on web browser by giving URL.
ClassXII
CLassXII
__init__.py Settings.py Urls.py Wsgi.py
student
migration __init__.py Admin.py Apps.py Models.py Tests.py
Views.py
Manage.py
Page 3
Creation and Saving of Webpage
Neha Tyagi, KV 5 Jaipur II Shift
• Create a webpage firstpage.html in Template folder.
• We will make its entry in a function in
views.py.
Page 4
Writing logic in Views.py
Neha Tyagi, KV 5 Jaipur II Shift
• Our next step is to write function for html page in views.py.
• In this file, we used to keep all those function which we want to
execute.
• Views works for rendering a page. For this, from student folder,
open the views.py in IDLE and create a view i.e. we will write a
function which will render and return the existing html file.
Page 5
Setting views in Urls.py
Neha Tyagi, KV 5 Jaipur II Shift
• Now we will access inner project folder (ClassXII) and add
following code in urls.py.
• Now save the file.
• And run django server.
•
here firstpage is the name that we will give on
web page (http://127.0.0.1:8000/firstpage)
Page 6
Displaying Webpage
Neha Tyagi, KV 5 Jaipur II Shift
• At last, we will open the web browser and will write the url of
our html page.
Page 7
Django Based web Applications Part -2
Neha Tyagi, KV 5 Jaipur II Shift
• In this part we will learn to add various
components on a web page and also learn the
method to send the data from webpage to server.
• Use of Get Method and POST Method.
• Saving data inputted on a Webpage to a csv file.
• Little DTL (Django Template Language) for this
purpose.
• We will develop a small application for this.
Page 8
KVS
KVS
__init__.py Settings.py Urls.py Wsgi.py
teacher
migration __init__.py Admin.py Apps.py Models.py Tests.py Views.py
Manage.py Template
first.html Stuentry.html
Example
Neha Tyagi, KV 5 Jaipur II Shift
• Lets take an example.
We will use stud.csv file to
store data.
Page 9
Views.py file
Neha Tyagi, KV 5 Jaipur II Shift
first.html file will open by this.
studentry.html file will open by this.
Page 10
urls.py file
Neha Tyagi, KV 5 Jaipur II Shift
runserver
Page 11
first.html file
Neha Tyagi, KV 5 Jaipur II Shift
For Navigation
See these names carefully. These are the names which were sent
from views via dictionary.
DTL syntax
Page 12
stuenytry.html file
Neha Tyagi, KV 5 Jaipur II Shift
Page 13
Opening First.html in browser
Neha Tyagi, KV 5 Jaipur II Shift
This data is sent by show() of
views.py , one by even variable
and other by name variable.
Page 14
Opening stuentry.html in browser
Neha Tyagi, KV 5 Jaipur II Shift
Page 15
What is HTTP?
Neha Tyagi, KV 5 Jaipur II Shift
• http is a collection of the protocols which carried
out the communication between client and server.
• They work as request-response protocol between
client and server.
• A web browser is a client and any application
which host the website can be a server.
• Two methods are used for this GET and POST.
• We have used both the methods in this chapter.
Page 16
Django Template Language
Neha Tyagi, KV 5 Jaipur II Shift
• In this chapter we have used some DTL.
• For detailed information of DTL, click the following
links-
https://docs.djangoproject.com/en/2.2/ref/templates/language/
https://www.tutorialspoint.com/django/django_template_system.htm
Page 17
Thank you
please follow us on our blog-
Neha Tyagi, KV 5 Jaipur II Shift
www.pythontrends.wordpress.com