Top Banner
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
17

Django Based Web Application Part - II · 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

Mar 19, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Django Based Web Application Part - II · 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

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: Django Based Web Application Part - II · 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

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: Django Based Web Application Part - II · 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

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: Django Based Web Application Part - II · 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

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: Django Based Web Application Part - II · 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

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: Django Based Web Application Part - II · 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

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 Application Part - II · 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

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: Django Based Web Application Part - II · 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

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: Django Based Web Application Part - II · 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

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: Django Based Web Application Part - II · 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

urls.py file

Neha Tyagi, KV 5 Jaipur II Shift

runserver

Page 11: Django Based Web Application Part - II · 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

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: Django Based Web Application Part - II · 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

stuenytry.html file

Neha Tyagi, KV 5 Jaipur II Shift

Page 13: Django Based Web Application Part - II · 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

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: Django Based Web Application Part - II · 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

Opening stuentry.html in browser

Neha Tyagi, KV 5 Jaipur II Shift

Page 15: Django Based Web Application Part - II · 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

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 Based Web Application Part - II · 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

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: Django Based Web Application Part - II · 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

Thank you

please follow us on our blog-

Neha Tyagi, KV 5 Jaipur II Shift

www.pythontrends.wordpress.com