0% found this document useful (0 votes)
51 views91 pages

Django The Ultimate Beginners Handbook - Mahesh Kumar

The document is a comprehensive beginner's handbook on Django, aimed at students and aspiring engineers interested in web development. It covers essential concepts, features, and the MVC-MVT architecture of Django, emphasizing its advantages such as speed, security, and scalability. The guide also includes practical instructions for setting up Django and creating web applications from scratch.

Uploaded by

stepkans
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)
51 views91 pages

Django The Ultimate Beginners Handbook - Mahesh Kumar

The document is a comprehensive beginner's handbook on Django, aimed at students and aspiring engineers interested in web development. It covers essential concepts, features, and the MVC-MVT architecture of Django, emphasizing its advantages such as speed, security, and scalability. The guide also includes practical instructions for setting up Django and creating web applications from scratch.

Uploaded by

stepkans
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/ 91

Django

THE ULTIMATE
Beginner’s Handbook
In this book all the important concepts of Django are explained,
which are more required in Web Development.

Author
Mahesh Kumar

Dedicate-
This book is for all those students who want to learn how to create Program for web
development. And if you want to make projects based on your ideas, then all of them
can take help of this book. With the help of this book, from 8 class students to 12 class
students. This book is also for all those students. Those who either doing engineering or
want to do engineering (Electronics Engineering, Electronics Communication
Engineering, Computer Science Engineering, Information Technology Engineering).
This book will help them to complete their basic for all of them. After reading this book
and using all its formulas, you will found the increment in your knowledge, And I can
say this with conviction.
hey guys today's session we'll be focusing on Django so Django is nothing
but a web development framework so without wasting any more time let's
move ahead and look at today's agenda

so these are the topics that we'll be covering in this session so we'll start
with the session by first discussing why do we need Django framework
once we get an answer to it will they understand what exactly is Django
after that we'll dig deeper into MVC MBT pattern that Django offers and
then we'll get started with it so here we'll start building a web application
from scratch and then moving on to some advanced concepts with it next
we'll be discussing some of the components or you can say the building
blocks of Django along with the packet all demonstration and finally
towards the end I'll be showing you a project which is a website where I
have incorporated all the components and some advanced stuff to make the
website look better so these are topics that will be covered in today's session
so let's get started with the very first topic that is why do we need Django
framework so Django is a Python web framework but why a framework

Why Django framework?


so first let's understand what exactly is a framework so a framework is
nothing but a structure or you can say a placeholder where you can place all
your components so this has some tools or libraries which reduces all your
manual efforts so let me give you a simple example so that you can relate to
it very easy let's say you have to cut a piece of paper with some dimension
let's say 5 centimeter by 5 centimeter surely you can do that but what if I
say you have to do the same with other 50-100 pieces in this case you won't
be measuring hundred times right so obviously you'll figure out an
alternative but you can repeat the same task for you so in this example what
you can do you can create a frame of the same dimension and then with the
help of it you would be able to cut those hundred pieces in lesser time so
this is where a frame book helps you so similarly in Django it performs the
same type of task or some repetitive codes that can be done in a single goal
now we know that Django is based on a very powerful language that is
Python so Django is a Python based web framework so Django contains
some codes or libraries it help you simplify your web operation let's say
whenever you create a website or say HTML you need to write some code
now what if you want the same Aran's or the same HTML for different links
in your website or different pages in your website now one way of doing it
is to copy the same HTML and paste it to different pages or you can just
simply template eyes it now what exactly this mean so what django does for
you it basically automates your repetitive stuff so django provides templates
where you just need to create one and you can link it with different pages
now don't worry guys I'll be talking about these templates in for Thermo
slides apart from these templates django offers a lot of things which surely
be very useful for you so that is how django is winning now apart from this
django has advantages like it has a built-in admin panel it has RM which
helps in data operations and many other things so now we know why
django is preferred over other frameworks or why django is actually used so
now let us go ahead and understand what exactly is jungle so django is a
high-level and has an MVC

What is Django?

MVT architecture now MVC stands for Model View controller and MVC
stands for Model View template so don't worry guys we'll be discussing this
architecture in further most slides but first let's get a clearer picture of what
exactly Django is so we know that Django is built on a powerful language
status Python now it also contains some tools and open-source libraries
which makes a life of a web developer much easier as it helps him to build
a very easy flexible scalable and a maintainable web application so to
summarize in Django is used for creating web application that is the soft
sphere which is backed up by a database now it includes some kind of
interactivity that operates through a browser so Django framework just
provides your structure and some common methods for making this kind of
software so now let us move on to different features of Django
or what Django has to offer us so the very first feature of Django is it is fast
now how it is fast now Jambu is faster because it is very easy to code here
and it's very good whenever you have to meet some deadlines so that is the
very first reason why Django is preferred over any other frame book next
Django is fully loaded which means it has in numerous packages and
libraries to offer so instead of coding all the use those packages or use the
libraries which are already developed by django developers next django is
very secure so the security of any application is one of the major factor of
concern for any developer now with django you do not have to worry about
that and it's already taken care of and then django is scalable so django
divides the entire project in multiple components or you can say
applications now let's say you have to add another feature later on or you
just want to make changes in one of the existing features so what you can
do you can always go back to the code and change according to your wish
or you can also do one thing you can just go to your code just create a new
app and then link it by our URL so this is how a django is extremely
scalable next let us move ahead and look at the MVC MVT pattern that
django follows so I've already talked about it that MVC stands for Model
View controller and MVC stands
Django Architecture: MVC-MVT Pattern for Model View template so as
you can see here
you have three components that is Model View and a controller so model
basically represents your database or you can say it is responsible for
storing and maintenance of data next is your view so view is used for the
presentation part or you can say it displays the request portion of data to the
user and here is your controller so controller regulates the interaction
between the model and the view so this is all about Model View controller
then we have Model View template functionalities are exactly the same
model stands for the storing of data views just for the representation part
and here template is something new so people also already discuss that how
you can use template and how you can represent your data to the user so
this is how django MVC and MVP pattern are different now django itself's
take care of the controller part so it doesn't need a controller so that is a
major advantage of django now let us move ahead and look at the
architecture or how this nbcnb deepak trim actually works now as you can
see in this image
so here we have model so model represents your database or where your
data has been stored and then you have template so template can be a web
application or front-end as well now when I combine these two I have a
view and to connect to that view this is going to be a specific URL also we
can have a separate URL for different views now Django is an interface or
you can say the middleman as it just helps the user to connect to the exact
URL this is how Django works so I hope you got a basic understanding of
how Django works so what exactly happens is just a developer provides the
model the view and template just Maps it to a URL and Django just
performs the magic and serves it to the user so this is how Django works
now enough of practical knowledge so let's move on to the hands-on part
we will first create a basic application from Django Web Development
Example scratch so let's get started with it now to create a web application
you first need to install Django so for that first step is to go to this link and
then install the latest version of Django now before going ahead and
installing Django in a system we know that we are using Python to develop
website so the first thing that we need is Python now I think you get this
must be aware of the Python and its programming because that is what
we're using here so just to verify it that you have Python installed in your
system or not just go to the command prompt

and python version so I'll go to my command prompt I'll run this as an


administrator
now why administrator because if they're using any other operating systems
such as Linux or Mac you can use sudo commands just to access the super
user privileges but in Windows you don't have sudo so that is where
advocator comes in so here what we have to do you just have to type in
Python - - version so this will display the kind question that I'm using so
currently I'm using Python 3 point 6 point 1
so since I have Python now let me go forward and install Django in my
system so I just have to open my Google and I have to type in Django
documentation so this will link up to my official documentation of Django

so here you can see this download tab so just click on that
so once you click on that you will be redirected to this page which says that
you just have to type in pip install Django and with the latest version so
right now the latest official version is one point eleven point seven
also the next thing that you need to check is that do you have Pippen stalled
or not now what is pip pip is just a tool that allows you to download things
online so once you're done with it you can go to your command prompt and
then you can check whether Django exists your system or not so once we
have this command we can go back to a command prompt and see whether
we have Django installed or not so I will go again to my command prompt
so I have closed it by mistake so let me just open the game for you so this
command says tip install Django with the latest version that is one point
equal to equal to one point one one now as you can see here my ladies
William Django is installed and what they have done they have uninstalled
my previous version that was one point eleven point four so now it has
successfully uninstalled this version
and currently my Django one point eleven point seven is installed in my
system so let me go to any IDE and let me help you to create a basic web
application so as we know there different idea is that you can work on but I
will be preferring PyCharm because it is very easy and it is very reliable so
let me open my pycharm so this is my jetbrains by some community edition
so it'll just take a few seconds so now it's loading my existing project now I
don't want to see my existing project inspired to create new one so there are
two methods to create it so either you can use a pychamp down there itself
or you can itself go to my files directory and create any directory and then
you can lower it to pie chart so I'll show you both ways so let me go to my
file directory and let me see where I can place a new folder settle create a
new folder here with the name ed Eureka so now I'm inside my head
Science folder now what I can do here I can either create a fold over here
and name it as a Django project or what I can do I can just simply go to my
pie charm open the terminal' from here and I can create a project using
terminal so for creating a new project you just have to type in this command
Django admin start project followed by the name of your project so let's say
the name of the project is my project or let's say first project so once you hit
enter it will just take two seconds and here as you can see your first project
has been created so once you go into it you will see another container with
the same name and one man is file so what is this so let me just go back to
my presentation and let's see what exactly these are so as you can see have
already created this project first project now
ideally the directory where I have placed this project it somewhat looks like
this so it has first project so it was containing two files which was managed
at me by file and the first project and inside first project they were certain
file so let me go back to my files and if I click on first project it tells me that
there are more files that is in it settings URLs and WSGI so you can go
back to presentation and let me explain all these files so as you've already
seen this is my project structure so first project is the name of the project
that I've just created and inside that Django has automatically two files one
is managed or py and the other one is first project so inside this first project
which is a container that is provided by Django with the same name and
side of the project it basically contains some set of default files with it
which is in it that py settings URLs and WSGI so let me go into detail and
let me help you understand the structure of the project so as you can see in
the left side so this is my project structure
So this is the name of the project that I've just created so you can rename it
to anything you want to now inside this

I have one loop container with Django automatically creates with the same
name as out of the project so this is basically the actual Python package
which contains some default files now what are those default files it is
image settings URLs and WSGI so let me go one by one and explain you all
of these now in it tells python that

this is to be created like a packet so Django has some different rules that
you need to follow next is your settings

now this file contains all your settings or the configurations of your website
so again this is kind of your main hub so inside this you have an option
called as installed app where you have to add the application that you will
be creating so this is one of the most important things that you need to do so
every time you add an application you have to manually add it here also
there are some other stuff like secret key and all that so we will go into
details when you actually see this settings.py file next is a URL file

so this is kind of your main control of the website which basically connects
all your links of the project with the view next is a WSGI file
So this is basically for Douglas J compatible web services which acts as an
entry point to serve your project and finally towards the end we have
manager py file that

basically interacts with your Django project so this is all about the structure
that Django follows so now let us go ahead and go to my pie chart where
we start building our own application so I already inside my first project so
now let me just open from here so I go to the same location and going to
Yoshi then Eddie a car so this is where my project is so I just load it up
from here so as we have already seen this is my project name it has two
files at its project first project with the same name and then the manage.py
file that interacts with the jungle so once we go into this project we have in
it settings URLs and WSGI that we have just discussed
now what is the first step that we have to do so now we have to create an
application so before going to create an application

let's go to my server and let's run my server so for running a server you just
have to type in pipe and manage dot py and runs over this is Dan so let me
just go to my google and type in localhost so here you can write your local
IP or you can say the local host which is not accessible outside your home
network
it is only accessible inside your network so now it says that it worked now
let me go back to my pycharm and let's see how you can create an
application and display a view to it so now for creating an application you
just go to a terminal and just type in Python managed or py start a panda
name of the application

so let me name it as first application or stop so as you can see here we have
some extra files added to this up now what are these so in it we have
already discussed then is the admin so admin is basically for administrator
so I guess I've already told you that Django itself provide an inbuilt admin
panel so we'll look into that after some time and then is your apps folder
which basically says that this is your configurations and the name of the
application is firstapp for now then is your models
so models is nothing but it contains your data base and submitted it over
here then is your test

so test you can just leave it for now because right now we are not creating
any test cases but yes in the further sessions we'll be creating our own test
cases as well and last is your view

so we have already discussed in the MVC NBT architecture which basically


stands for the presentation so the first thing that you need to do is to go to
your settings of your main project that is first project and let me go to your
settings of this
so I'm going to told you that we have something called as installed app
where you have to manually write the application that you are working on
so I have created the application which is named as first app
so I'll manually write here so other things are just by default so I don't have
to worry about that so here we have some templates which is default given
by Django so here this is wsgi application so this is also I've discussed and
then we have databases so Django provides some inbuilt database that is
sequel ID and Django has a strong authentication so we'll be discussing
about this is when also the important part of settings.py file is the secret key
so remember and never share your secret key with someone else so for
example if you want to put your project on github or somewhere else so do
not put the secret key because this is used for encryption so basically what
is that it basically encrypts your session and everything which is inside this
project can be taken by someone else so that is might never share your
secret key so once we clear with settings our people are filing now let's hop
into the next file that is urls.py file now here
what it says it it just has one URL which basically points it to admin side so
here we create our own URL which say it should go to our web application
so let me just copy this and paste it over here so this URL starts from a
regular expression so here I don't want to go to admin so I can so I can have
this so here if you are aware of regular expression it is well and good else
you just get a basic introduction to what is its regular expression because
you will not be covering this in this session but yes you should be aware of
it so just to give an introduction here this character represents the beginning
of the shrink and dollar represents end of the shrink so here I don't want to
go to my admin.site.urls so in spite of that I just include my application that
I've just created so that is firstapp firstapp.urls so now I have to import
include as well so we know that this firstapp.urls doesn't exist now
so what we'll do we'll go to this firstapp and we'll create a URL for it so
before going to create firstapp.urls first let's see what we have to display
and then we can give a link to that view here is my view start be my file so
this is my views of py5 so inside this we need to imports of HTTP response
so for that you have to type in from django import HTTP response so we
don't need this for now and here we create a first method say define index
and inside this will send a request and here we'll write whatever you have to
return same I have to return HTTP response and inside this I will be writing
and he takes you one to write so I want this text in header two and I'll say
hey everyone when come to this Django tutorial clothes of my h2 back so
now let me just remove these errors so this is all in small step as well so
now everything is done so what next so hey I need to link with a URL so
the whenever a person goes to that URL it just displays me this view
so let me just go back to my application and here I just create one more file

that is URL stop py5 URLs so inside my URL file


first of all I import my URL so for that I have to just type in and then I have
to write from period import view so here period is basically a relative view
or you can say you're importing from the current view so inside this we
have to write a URL pattern so I already told you that this URL in the
regular expression form so this is my regular expression where your carrot
stands for the beginning of the string your dollar stands for the ending of
the string and after that we'll be just giving we use dot index which is the
name of the function that we have just defined in views.py file and then a
namespace to it so you can write any name to let me put AZ index only so
now we have specified the URL pattern now what does it say whenever
user goes to this application it will open this view which has an index
function so if we go to this function it has this index function which takes
the request and returns the HTTP response so this is my response so let me
just go to my server and let's just start the server so again I have to type in
Python manager py and runs over
so here it gives me an error that it cannot import name is a loose one so here
I have imported this Django I just have to type in HTTP so I guess it's been
working fine now

so let's just check this once again so what you've done till now we have just
created a project so inside this project we have you our insert py file which
is the main controller so here we already have admin URL I have included
one more URL that is full staff that URL so this URL we have created by
ourselves
so I'll go to this firstapp that URLs so this is my first app I go to URL

so in this file we have declared URL patterns which says just go to my


views and see the index method and along with the name space so they
people directly redirect to the views
which has a method named as index and this method will take the request
and return your HTTP spots so I think this flow is right so let me just go to
my terminal and runserver

so here if I go to my local host so here it says that Jiang who tried these
URL patterns in this order

so have we gone to admin no haven't gone to first app no so what we need


to do we need to go to the application which we have created so it says
firstapp

say yes my view has been displayed here


so whatever we have written in the view store py file it says hey everyone
welcome to Django Tutorial and this is what it actually represents us you
can also redesign it and bring your phone in the way you want to so this is a
simple application that we have created now let me go back to the
presentation and let's see what else we have so hence we have successfully
build this web application

which displays the view next let us see what are the different components or
you can say the building blocks of Django

so there are many building blocks of Django so let's


Components of Python Django have a look on each one of them so Django
has these set of components or you can say building blocks

so let's just start it with the very first building block that is you're wearing
now ORM stands for object relational Mapper so what happens exactly
ORM. ORM is basically you can design or you can define your own data
model so what exactly is a data model so whenever we talk about data base
or when we talk about the data or related things ORM comes into the
picture so it's a code library that automates the transfer of data stored in
relational database tables into the objects so if you have say here first of all
get imported models and then we have created a class called as employees
now inside this class employees I have two pins witches firstname and
lastname so this is what a model is storing so it firstname should be of
maximum 10 and lastname should be of Aksum length 10 and after that we
need this string method so that is why it is returning self dot firstname so
this is how we can play with objects and you can retrieve the information
present in any other database and you can see the results next very
important feature is URLs and views
so we have already discussed about URLs and views Django here
encourages a beautiful URL design so we have already talked about views
and how you can map a view with the URL so what we have done best
specified the URL pattern in the form of local expression and to say at
views on index. index is a function or you can say the method which is
defined in the view.py file and once we go to the view.py file if it says that
it has look Mathered index that accepts requests and returns HTTP response
so this is what we've already discussed in the basic application that we have
just created so I think you guys must be clear about these concepts and till
now guys if you have any problem or any kind of question that comes into
your mind just come in below this video and we'll be happy to help you
with the same so next component is your templates
so templates are basically your front-end or you can save your view has
been displayed it is for front-end developer who likes working with HTML
and everything like that so I think you must remember that in the
settings.py file I showed you this temporary directory so let me just go to
my PyCharm and just show you where this template directory is present so
this is what django provides

so you don't have to configure any template or anything like that django
does everything for you next we have a very important topic that is a form
so django provides a powerful form lighted now it handles all your security
or your HTML everything inside it so form is basically a collection of
elements which helps you enter the text it helps you select the options you
can manipulate your object and you can have the control all over it so as
you can see here I have created a form which has the fields first name last
name email and a button to register so basically this is a registration form so
let me go ahead and help you create a form in Django also in this form I
will be creating a template as well so that it will help you to relate how we
can create a view and how you can create a template with it so let me go
ahead and let me open my pie jump to create a form for you so now coming
back to a project we have view stop me by 5 where I have returned the
HTTP response now I will need this HTTP response now in fact I need a
template so for that I will return render which has a request then you
specify the part where a template is present and then we'll pass the
dictionary so now we have to create a form for this so what I do here I first
create a form so hey I'll be passing the big story that is context and inside
that I'll be having the key so let's say my key is my registration form and
farm is my instance so here as you can see this is my variable this is my
variable which is a class representation and then I have passed this context
which is a dictionary over here so this is my key and this is just the instance
of it
so what I have to do I have to create this index.html Basically where your
template is present so I first go to my first app then I'll create a new Python
file I can say html file
and hell I'll go to templates folder which has the same name as first
application and then my index dot HTML so this is my HTML format

now what I have to do in this HTML I have to create a form so after my


body I have to create a form so I'll type in form class so here I'll be
representing the path and then the method which is post so next I have to
light CSRF underscore token so I have already told you that Jango itself's
take care of the security so CSRF stands for cross-site best forgery so these
security features are taken care by Jango itself so inside this I will pass my
key which was my registration form just let me check it once to my
registration form it just copy and paste this and yes my form is done after
just closing body tag over here and yes it's done
now next one I have to do I have to create forms that py file in the
application so this is my first app and here I create a new Python file

that is forms

so first of all here we need some input so here I write from Django import
forms so this is a pre build thing in Django
so you don't have to create or write manually things so I create a class all
our registration forms so this is the instance that I am talking about now this
will basically allows you to access all the fields so inside this I will be
writing with fees so let's say I need first name I need max England to be 20
then I need last name and I need one more field that is an email field so I'll
simply write emails to form that email wait so now everything is done

to let me just go to my terminal let's see what happens when you run the
servo
so here it says that you have some unapplied migration so first you need to
migrate it so I just break the server using control-c so to migrate the project
I have to write Python manage.py migrate

so Jango literally grade it Auto really tells you what you have to perform
next or what is the problem you are getting the errors so once you click on
migrate it is migrating
so next if I run this project

let's see what happens

so my project is running so I will go to my project so oops it gives me an


error
that name registration form is not defined so let me go back to my project
and let's see where I have not defined this so I just made a silly mistake do
not add the so now I just go to my views and here this registration form is
still appearing as a day so what I will do here I'll first import registration
forms so I will do I will write help from period import registration form

so now the red signal has gone so this will work down let me go back to
terminal again and let's see what happens
so as soon as you click on the refresh button your form will be displayed

so here you have first name last name and an email ID so here in this first
name field if I save type a value that is Mahesh let's say the last name in
Kumar and any email ID that is let's say
[email protected]

now but we don't have any button or from where we can submit this
registration form so let me go back to my code and let's see where we can
add this so this is my views.py file so this is my template that is index or
HTML now here to add a button to it you just have to type in input type
which is a submit button and we can give a value or you can say name such
as register
so now when we go to this forum we have a baton as well to register

so here if we type in any values the data will not get ingested into it so why
this will not happen because we have not carried these are models for it and
from where you can create data models you have to create a separate file
that is a model store key by and then you have to create different objects for
it from where you can retrieve it now if you want to play around with this
registration form just go back to your code and just write but as under scope
P
so let's see what changes does it go so here the view has been changed

if I do as_table again

let's go to my first app and if i refresh it it represents in the tabular format


next if I write ul

and I'll click over it so it give me in the bullet points

so this is how you can play around with the templates so let me go back to
the presentation and let's see what else is left with them so we have covered
forms next we have authentication
so Django comes with a fully featured and secure authentication system so
Django handles user accounts the group's permission and all the cuckoo
based user sessions so now if you see at this code it already contains the
earth which basically represents the authentication so this is how Django
accepts take care of that authentication part next is your admin

so admin is the strongest part or you can save the main USP of Django so
Django provides an invade administration panel so this basically it takes
your data which is pink period in the models and then it will retrieve you so
this is how my admin panel looks like you have a user name and you have a
password so let me go back to my code and let me show you how exactly
an admin panel looks like so if I go to admin

so this is my username and password for now I don't have a username and
password so let me go back to my PI charm and let me create one for you so
i come out of the server first and for creating a super user you just have to
type in python managed or py create super user so here it will ask you for
username and it also gives me an option that we blank if you want to use
the same username that is Mahesh
so I will just leave it blank so it asked me an email address so it's just an
optional thing so the password it is very important so let's say I give a
password I again ask me a password so I've given a password which is too
short so let me just give a better password so here my super users created
successfully
so now I will go again back to server both let me just run my server
so now I have a username which is Mahesh and I've just set my password so
let me just type in here

so as you can see here


is my admin panel so here you have groups you have users you can add the
users so if you go to users

so you just have one user which is IO XI so if I want to delete it you can do
anything in this admin you can add to the users you can select them with it's
an admin or it's not an admin so you have raised options over here we can
also change the side we can logout and many other things so let me go back
to the presentation and let's see what else we need to cover so we covered
the administration part so this is how a Django provides a suite admin panel
so now let us move forward so next is internationalization
now internationalization basically translates your text in different languages
it doesn't care about locate specific formatting doesn't care about the time
numbers irrespective of the timezone so choose the home page with the
welcome message that is translated in a user's language so this is how
django keeps on winning hearts next we have the last feature which is
security
so I have already discussed some extent of security so django provides
multiple protection now it provides protection against clickjacking CSRF so
CSRF you already discussed in the forms so we have implemented this as
well they provides protection against experience action and remote code
execution so this was all about the building blocks of django let us move
forward with the
Python Django Project:
A web application project so here I have just create a demo website which
displays all your courses the description along with the date and time
backed up with the database so in this I have used few of the comples that
we have discussed and some of the advanced stuff so let me just showcase
the project view

so let me open my project


just in Mahesh and Django project django-tutorial

in concurrent winter so now let me just run the server


and let's see what exactly displays

oops I guess I have not improved with the manage.py file so let me do it
again

so inside django-tutorial demo


I have a manage.py file so again I have to run my server

So myself is now running so let me just open it


and I'm just go to localhost

So this is how my website looks like now here I have some static files and
some text displayed so here is my Python Django tutorial which is the
header of the website and here in the left hand side I have their - reiga logo
just below that I have a navigation bar which contain three tabs that is
Home tab courses tab and contacts tab after that in the same div container I
have placed four static files which says Science has live classes it has
export instruction it has to enforce and support and flexible scheduling and
towards the end in the footer I have given contact you can contact the
Science record support or educator for then we have Facebook the
Facebook page of Science opens up next we have YouTube so here I've
given the link which opens up the Science channel so this is how a website
looks like now if I go to home it will just say hey we will come to in
Science but if I go to courses so I do ever provide a lot of courses so here I
put a slider
37:31
which changes automatically with the number of object that it has so right
now I just have Django and Python so if we click on python

the detail description will be displayed

so python and the course subscription is below and when it was published
it's all written it's the date and time has been mentioned similarly if i go to
courses again same is case with django
django it displays

the description and the date and time with respect to it last we have contact
so encounter I have just displayed the view which says contact in support
and any record code which basically gives 24/7 support so this is how my
website looks like now in the courses tab I just have two objects slamming
go to admin page
and let's add few more courses so oily creator username for this project so
the user name is Mahesh and the password and specifying

so this is my ad mutation pattern that we have just displayed


now one more thing that you must be noticing over here is the courses now
here you have just let me pull it to here so inside courses I have a model
which is post so once we click on this

it has post
now here it displays just two objects now here I can add unlimited courses

now let's have to upload a new course which has a name let's say appear
and in description I just lied this is a new course so then you can just
provide the date you can select today and you can select the time is now and
then you just simply have to save it
so now as you can see the post has been added now

once you go back to your website he will see the course will be added well
just refresh this page where as you can see RPA is been added now

if I click on it it will display me the description the date and time


so this is how the website works so now let me just walk you through the
code of it so for that I just come out of my server

so this is my project structure


now the main application that I have is demo so I'll go to my project demo

and I'll see the settings or you can say the URLs

where the user has been hitting so there are three URLs the first is the
admin which is by default secondly I have created my dot URLs and then I
have create a separate application which is courses and I've given a separate
URL that is course is not URL so these are the two applications that I've
created and I've given a separate URL to it so now let me go to my first
application that is mine so I'll go to my application

I go to URLs.py

so here I've defined my URL patterns now we know that you are your
patterns are in the form of regular expressions so this is my home page
where we have a view where we have an index method which must be
placed in view and we have given a name space to it second we have
contact where again I have here a contact method and given a namespace to
it so let me just view these two methods in the views.py file

so here these two methods are defined so the very first method is index so
here we have again not returned the HTTP response so here what we have
done we have simply returned the templates so what I have done up I have
created a template which is home dot HTML and there I have passed
dictionary which has a key post and then it has post 1 and post 2 similarly
contacts I have created one more HTML that is basic to HTML and then I
have just passed a dictionary which has a kiosk content so this is my
dictionary and then I have passed the content to it which says contact
[email protected] so these are my two templates which says home.html
and basic.html so let me just go to my template folders and let's see what
exactly is their home and basic so as you can see here
it first extends header dot HTML and then it will just display this text that is
hey welcome to Erica so this is present in the ginger logic now if I go to
header.HTML which it has extracted so let me just go to header.HTML

and here your all HTML is present so this is my header part


where I have just displayed come to aid Eureka and then I have load some
static files which are the images now inside that I've also used some
bootstrap which has a link of this so if you come down you have a body
class

which has a diff container so if you guys are familiar with HTML so you
will really catch up this soon so inside this sub page for static file and the
text accordingly so here I have given the source of the image I've cleared
one more folder that is static and inside static I have my application then
you have folder name as image and then the name of the image so if you
see here I have a folder which is static then it has the same name as that of
my application and inside this I have already told you that I've used some
CSS
so this is the bootstrap that I've already downloaded so it's up to you you
want to use it or you don't wanna use it so just to represent this better I have
just downloaded the bootstrap and then I have just pulled over here so I'll
just show you from where you can download the bootstrap so I go to
Google and I'll just type in bootstrap
so this is the website from where you can download a bootstrap

so he'll it has a lot of things that you can practice so he'll say is download
bootstrap you now know the source and many other things are there now if
you see an examples you can find a million of examples over here so what
I've done I've just simply downloaded this bootstrap so this is a zip file that
comes with us so what I've done I've just extracted this folder and just paste
it over here so this file contains a CSS your phones and your JavaScript so
this already contains a lot of things

it has CSS it has themes and many other things now the one thing that I
have added is the image folder

now here if you see I have added these fixed images in the website if you
click on that so this is the first image that I've added to the website
let me show you where this image is exactly on the website so this is the
first image which has a name of life classes so this is my first image
similarly there is second image

and similarly I have other feature images


as well so this is my feature - this is my picture 3 and this is my feature 4

so these are all the static files that are uploaded to this website so here in
my div tag I have given the source
a static my image and the name of my image similarly I have done it for all
the images next I have created a navigation bar

which is there in the left hand side so this is my navigation bar which
contains three tabs that is home courses and contacts so this is my home
courses and contacts so here I've used the list which goes to different URLs
at the same time so if I go to my home I have a different view which is
displayed if I go to courses I have different view and similarly with contact
so this is all about my left navigation bar again I have created one more dip
tag
where I have placed three static files so next I've also created one more dip
tag

where I have placed the slider so this is a slider that I'm talking about this is
code for slider and in the end I've just added a footer
so input I have just added the hyperlinks to it so if you click on 'contact a
new URL will open if you click on facebook a new link will open and
similarly with the YouTube so when my application is completed now let
me go to the other application which is courses so if you go to this URLs of
the main project

this I have already covered so next let us go to the courses application and
just hop into courses that URLs calm so courses I'll go to URLs.py file
so here I've created a URL pattern now here I've already told you that in
courses I have created a list so the list it collects different objects which is
created in a admin panel so here I have written a query set which says post
which is the name of my model and then we have selected all the objects
and then we have ordered by date now - it represents the descending order
and if you want to place a limit to it you can place a limit let's say 25 so
only 25 courses can come at one go next I create one more template which
is courses of HTML and if you need a detail description to it you have to
create another URL which has a PK which is a primary key now you will
not create a primary key Django does it for you so here it will represent
your first column in the model so here I have specified the model is my post
and here I have displayed one more template which is inside my courses
and this is post on HTM so let me go to courses and post at HTM so inside
my templates I have two templates

that is courses and post addition table


so this is the HTML for my slider so it's again extending my main HTML
which is header dot HTML but inheritance is taking place by the keyword
that is extends now everything is inside your ginger logic now here I have
started a loop which says for post in object list now object list is the list of
all the objects which are there in post now what is post so post is my model

gentleman first go to my models so here I have paid one model now I have
clear class which is post I have different feels like course description and
date so this course has the maximum 140 description it has textfield love
this and similarly the date I have cleared one more method which basically
returns your self dot course so once your model has been created let me go
back to my courses on HTML

and here apply it for loop it says yet each object should come in the list so
here I have displayed the post date day it should come in this format to
display the year first and the month followed by the date after that I've just
given a hyperlink which says courses and it will fetch the post ID which is
the work of primary key basically it will just tell which column or which
courses it has picked up from so this is my slider next is your post of
HTML

so in this post of HTML I have just inherit the same header or HTML file
and inside this I have to display the course description and Dave now if you
notice here I have written post or body-safe and line breaks so if you go to
my website and if I go to inspect
so you can actually see this in different formats let's see if you want to see
this website in iPhone 6

this is how my website will look like in iPhone 6


similarly you can try for different devices

as well
also if I close these tabs now similarly if I open my tab and if I squeeze
this window

it will not change anything so this is what these things do so this was all
about my project so I hope you get a simple understanding of what exactly
all these components and how exactly these components work so with that
I'll just wrap up my session so in this session here
first talk about Django famed book Ohio finval and Django is used after
that they've understood what exactly is Django and what are the different
features of Django once we got what exactly is Django if we move on to the
embassy enmity pattern the Django follows next we just got started with
Django and they appeared a basic web applications we just displays the
HTTP response after that we have gone to different components or you can
say the building blocks of Django and finally it was the end I have
showcased my website where I've implemented different components and
how those components work so this was all about Django so I hope you
guys liked the session now if you guys have any doubts or any query stated
to any of the concepts that I have discussed you can just leave a comment
and we'll fly to it at the earliest thank you so much have a great day
goodbye happy wicked I hope you enjoyed this.

OceanofPDF.com

You might also like