Django Based Web Application
Part - II
CBSE Syllabus Based
Class -12
CHAPTER -15 CS
CHAPTER-9 IP
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
What we learnt in Part-I?
• 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 student Manage.py
__init__.py Settings.py Urls.py Wsgi.py
Admin.py Apps.py Models.py Tests.py
migration __init__.py Views.py
Neha Tyagi, KV 5 Jaipur II Shift
Creation and Saving of Webpage
• Create a webpage firstpage.html in Template folder.
• We will make its entry in a function in
views.py.
Neha Tyagi, KV 5 Jaipur II Shift
Writing logic in Views.py
• 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.
Neha Tyagi, KV 5 Jaipur II Shift
Setting views in Urls.py
• Now we will access inner project folder (ClassXII) and add
following code in urls.py.
here firstpage is the name that we will give on
web page (http://127.0.0.1:8000/firstpage)
• Now save the file.
• And run django server.
•
Neha Tyagi, KV 5 Jaipur II Shift
Displaying Webpage
• At last, we will open the web browser and will write the url of
our html page.
Neha Tyagi, KV 5 Jaipur II Shift
Django Based web Applications Part -2
• 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.
Neha Tyagi, KV 5 Jaipur II Shift
Example
• Lets take an example.
We will use
stud.csv file to
store data.
KVS
KVS teacher Manage.py Template
__init__.py Settings.py Urls.py Wsgi.py
first.html Stuentry.html
migration __init__.py Admin.py Apps.py Models.py Tests.py Views.py
Neha Tyagi, KV 5 Jaipur II Shift
Views.py file
first.html
file will
open by
this.
studentry.html
file will open by
this.
Neha Tyagi, KV 5 Jaipur II Shift
urls.py file
runserver
Neha Tyagi, KV 5 Jaipur II Shift
first.html file
See these names
carefully. These are the
names which were sent
from views via
dictionary.
DTL syntax
For Navigation
Neha Tyagi, KV 5 Jaipur II Shift
stuenytry.html file
Neha Tyagi, KV 5 Jaipur II Shift
Opening First.html in browser
This data is sent by show() of
views.py , one by even variable
and other by name variable.
Neha Tyagi, KV 5 Jaipur II Shift
Opening stuentry.html in browser
Neha Tyagi, KV 5 Jaipur II Shift
What is HTTP?
• 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.
Neha Tyagi, KV 5 Jaipur II Shift
Django Template Language
• 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
Neha Tyagi, KV 5 Jaipur II Shift
Thank you
please follow us on our blog-
www.pythontrends.wordpress.com
Neha Tyagi, KV 5 Jaipur II Shift