Python Web Development | Web Development Using Django | Python Django Tutorial | Edureka

Hey guys, welcome back to a new session
from Edureka. My name is Wajiha. And in this session, we will be learning something
very interesting which is web development using python. So before we begin just
make sure you subscribe to our Channel and hit
the Bell icon to stay updated with all the latest
Edureka videos. Coming back towards the session. Let’s take a quick look at
all that’s in store over here for you guys to begin with. We shall first cover
some Basics about Python and then we shall look at why python is used for
web development following this we shall take a look at some of the important
web development libraries or Frameworks of python
in today’s session. I’ll be using
the Django framework to develop a sample website. So let’s just look at what
the attractive combination of python and Django
offers us after that. We shall move on straight away. Install Django and finally, I’ll be showing you
how to create a sample website from scratch. So I hope everyone’s
clear with this. So now let’s move on
towards the first topic of this session to brush up
a few Basics about python guys. Python is an interpreted
high-level language, which can be treated
in an object-oriented sequential or a procedural manner. It also provides high level
built in data structures, which are merged
with Dynamic typing and dynamic binding semantics that make it very attractive for application development
web development is nothing but the task
of developing websites that can be hosted by
the internet it varies from simple page
to complex websites. For example, Facebook Etc. Now that we’ve covered
the basics of python. Let’s move on and see why python
is used for web development guys python allows you
to build web applications. Dynamically. It’s a very stable
language it also. Grunts, you used to build multi-protocol Network
applications the fact of python being flexible easy-to-use and it’s quick processing are
just a few reasons to mention for its worth
in web development. Now that I’ve explained
about the features of python, let’s take a walk
through some of the libraries that python provides for web development guys python
provides a number of libraries for web development. Some of the important ones
are cherry pie Django web to pipe pyramid turbo gears and flask among these
in today’s session. I’ll be using
the Django framework. So now y’all might be wondering
why Django and why not any other Library Django is
truly the best python library for web development. It’s written purely in Python and it’s fast you
can create websites within a matter of a few hours. It’s fully loaded with all the required tools
to create websites and it’s very secure Beat YouTube your Dropbox
Google or in Graham all these internet Giant’s
rely on Jango. So with this I think
I’ve given you enough for why I’ve chosen Django
over the other libraries. Okay. So guys now let’s move on to see how to install Django
before installing Django. You will have to install python
on your PC’s to do that. You can go to the official
python web site and download it from there. I’ll be showing you guys shortly how to do the same
after downloading python. You’ll have to
finish its installation and setup process following that I’ll be showing
you all how to set the python home variable. This is done to make
your IDE look for python as to where its installed on your PC after that you’ll have
to download pycharm and install the same on your PC. Finally. You’ll have to open
the pycharm terminal and use the command to install Django. Okay. So now let me go on
towards the browser and show y’all
how to download python as you can see on the screen. This is the official
python web site from where you can download python. If you’re using
a Windows platform, you can download python using
this option over here or if you are using Mac Linux
or any other operating system, you can use
the corresponding options. Once the download is completed
you will have to finish with the setup since I’ve already
installed it over here. It does not give me
an install option. It just gives me
an option to modify repair or uninstall this. Okay, so after installing
this on your PC go to the advanced system settings. Choose the option
of environment variables and over here choose
the new Option and give the name as python underscore home. For the value of this variable. You’ll have to copy the path of where python has been
installed on your PC. To find where python
has been installed on your PC just search for Python and right-click on the same
and use open file location, as you can see over here. It shows me where
I’ve installed python now, I’ll copy this location and I’m
going to paste it as the value of this variable and use okay. After doing that look
for the path variable present in the system variables
and select edit. Go to the variable value and towards the end
of the value. If you do not find
a semicolon insert a semicolon. And after that type
python underscore home between two percentage symbols. Just like how I’ve done
it over here. Okay, so after that
just give okay. And close the settings. Once this is done. Your python location
will be visible to your IDE to download pycharm go
to the jetbrains website and download any version
of your choice guys. The community version is free. So you can download
this with ease. Okay, so I hope you are clear
with how to download and install these two. After downloading pycharm, you will have to
finish the installation and the setup process. Since it’s already
downloaded on my PC, I’ll jump onto my pycharm
and show you how to install G. Okay. So guys once you’re done
with the installation and setup of pycharm just
open up your pycharm and you should see
the following screen since you’ve newly
installed pycharm. You will not see any projects
that are present over here. So to create a new project go to file choose
the new project option and over here specify any new
project name that you want. I’ll just give the name
as web project. And I’ll use create. So I hope everyone’s clear with how to install
Python and pycharm. If you guys have any doubts, please do let me know
in the chat box and my team is here to help you. So guys, please make sure
you’ve subscribed to our channel to find more interesting videos
from Eddie Rekha. So as you can see over here
web project has been created within the current directory. So after this, I’ll just open up
the terminal and over here. I’ll use the command
pip install Django. It’s going to take awhile
to install Django guys. So when you’re installing Django along with Django
the SQL parse data base and the PYT set module
also gets installed. SQL bars is actually an on validating SQL
parser for python. It provides support
for parsing splitting and formatting SQL statements. Now, this is actually compatible with the versions
of python from 2.7. The pyd is at module is
actually a third party module that brings the Alston TZ
database into python tease. It actually stands
for time zone guys, this Library allows
accurate and cross-platform time zone calculations using
python 2 point 4 or higher. It also solves the issue
of ambiguous times. Okay. So once Django
has been installed, it will throw a message saying
successfully installed Django with its version
and the version of the PYT that module and the SQL parse
now to cross check the installation of Django go
to your command prompt. and use the command python –
M Django – – version now when you use
this command it should return the version of Django
that’s been installed. So I hope everyone
is getting the same. Okay. So now let’s close this. I hope everyone’s clear
with this for any routes guys. Please do let me know
in the chat box because my team is
always here to help you. So now to create
a Django project within this project. I’ll use the command Django –
admin start project. And I’ll give a name
to my project. Let me give the name
as demo project. Okay. So now a demo project has been created within
the web project directory. Let me open this directory and here it shows
the web project that’s been created. Let me just go
to the presentation mode and show you I’ll go to view
and I’ll select the files that I want and the terminal as you can see over here within
the demo project directory. There’s another directory
with the same name as my project and there is a file
created by Django called as the manage dot py file. The man is not py file is
actually a command line utility that lets you interact
with the Django project. Don’t worry guys. We’ll be using
this many a times. So you’ll get
familiar with this. Now. Let me just open
this directory and see what’s present within it
the first file that’s created within this directory is the in it dot p y now the in it dot p y is actually
an empty directory which is considered
to be a package. After that. There is something called as
the settings dot P why this actually consists of all the But unnecessary for
the current project after that, it’s URLs dot py URL start py consists of all the URL declarations
for this project and finally the wsgi dot py file where wsgi stands for
web server Gateway interface. Now, this is actually
a calling convention guys for web servers to forward
requests to web applications or other servers. So I hope everyone’s
clear on till here if you have any doubts do let
me know in the chat box. Okay, so now to check if I’m able to connect
from my project to the web server. I’ll just get into my project
using the CD command. And after this I’ll use
Python managed at py. run server Like I told you the manage dot py5 will help
me connect to the server. So this will return
an IP address. So when you click
on that address, you will see a screen
with a rocket which is ready to take off. So congratulations guys. Your rocket is ready to move on which means you’re all set
to create your own web sites. So I know that after this everyone
would be excited to create their own websites to do so, I’ll just get back to my pycharm
and show you guys what exactly you must do
to create your own websites. Okay, so to create my website, all I’m going to do is create
an app within my demo project. I’ll just return the control
to my terminal using Ctrl C and over here. I’ll create a new app
within my project. Please make a note guys that one project can have
n number of apps which means you can include
any number of apps within your project. To create an app. I’ll use the same command which is python manage dot p y
and instead of run server. I’ll use the start app command
and I’ll give a name to my app. Let me just give
the name as demo app. So now an app has been created
within my project. Let me just open this up
to show you all what’s present within this demo app. So just like how Django had created files
for us within our project when we created a new app Django has created
the necessary files for us. So this is what Django does it writes
all the necessary code. And all you have to do is write
your web site specific codes and just modify the files that are present and add
your own files as per your choice. The first file that I’m going to open over
here is views dot p y and as you can see over
here Django has already imported render for me now. I want to use
the HTTP response function. So I’ll use from Django http. Import HTTP response, please. Be careful with
your Spelling’s guys. Now within this file
create a new function using the d e f key word and I’ll give the name
of the function as high to this function. I’ll pass one parameter
which is request. Within this function. I’ll just write
one return statement. Using the HTTP
response function. I actually want this function
to return a message saying that this is the homepage
of my website. I’ll just put it as a string and
I’ll use the H1 tag for this. This is my home page. And I’ll close the H1 tag / H 1. So as you can see
over here pycharm has highlighted this line because I’m using
the HTTP response function. The first line of my code
is not highlighted because I’m not using the render
function anywhere as of now. I will not be using
the render function. However, I will be showing you
how to use this later on. Okay. Now I’ve created
views for my project but I will not be able
to connect this file to the URL stood py which is present in the demo app to connect
views dot p y to this URLs dot p y I’ll have to create
another URLs dot p y within the demo app
directory and connect that URLs dot p y
to the URL stood py which is present
in the demo project. Don’t get confused guys. I’ll be doing it over here and the video will be
available after this in case you have any doubts
you can go through it again. So I’ll just create
a new file within the sap. It’s going to be a python file. I’ll give the name
as URL start py. And I’ll say okay this URL stood
py is actually very similar to the URLs that py which is present
in the demo project file open the URLs to py present
in the demo project directory. And I’ll copy the from statement which is from Django
dot URLs import part and the URL pattern list. I’ll just copy this and I’ll go to URL start
py present in my app and I’ll paste it over
here now over here since I want to map the views
dot p y into this URL start py What I’m going
to do is use from. Which means from
the current directory. Import views and within
the URLs pattern I do not want this admin path. So I’ll just remove this and
I’ll leave the name as blank. Because I want this to be mapped
to my homepage and over here. I’ll use views dot. Hi. It’s just the name
of my function and I’ll give a name to this path. You can give any name
of your choice. Let me just give the name
as homepage home – page. Okay. So after this what I have to do is
map this URLs dot p y to the URL stood py which is
present in the demo app, so I’ll open the URL start py
present in the demo app and over here. I’ll Create A New Path
and I’ll give an empty string because I wanted to be mapped
to my homepage. Like I already told you all. Sorry guys. I’ll have to import
the include function also. So from Django dot URLs, I’ll import the
include function. And over here, I’m going to use
the include function. I’ll map the URL stood py
present in my demo app. And I’ll close this. So after this, let me just go
to my terminal and use Python manage dot py run server. I’ve just made a name mistake
this is demo app. Okay, so as you
can see over here, it has returned
to IP address again. I’ll click on this IP address. Congratulations guys
instead of the rocket which we were seeing previously
which was the default page. My website is displaying
whatever I want it to display. So this was the message I wanted to display
on my home page and it shows that this is my home page. So now I’ll get back
to my pycharm and I’ll see how I can modify this page
to create a website. I’ll return the control back
to my terminal using Ctrl C. So to write HTML code
within this project. All you have to do is
create a new directory within your app directory. And that will be
the templates directory. Now. These will be the templates
that are specific to this project and instead
of looking elsewhere. Django will look
into this directory for the necessary templates. Within the templates directory, I will create a new directory
with the same name as my app. Don’t get confused with this guy’s this is
actually the Django convention which helps you write
Project Specific code So within this demo app, I want to write
the HTML code. So I’ll create a new HTML file
to write all the HTML code that I want. I’ll just give the name as
High Dot HTML and I’ll say okay. So as you can see over here
Django has already written the minimum HTML code for me. I’ll just change the title
to Eddie recognized. You can give any title of
your choice and within the body. I’ll just write Hi and after this I’ll open
the app store py file. I’ll copy the name
of this class and then go to settings dot py present in My Demo project
and over here. I look for installed apps. Remember that whenever
you create new apps, you’ll have to add it over
here then within a string give the name of the app, which is demo app. Please be very careful
with the spelling’s because if you make any mistakes, it’s going to throw a lot
of errors and you’ll not be able to understand why
it’s throwing such errors and for beginners it
sometimes gets very confusing to debug these errors. So just be careful over there. So let me get back
to this name of my app, which is demo app dot apps dot
the name of the class that we’ve copied from there. I’ll just paste it over here and I’ll specify a comma
after this now from here. I’ll go back
to my views dot py file and instead of
this HTTP response. I’ll be using
the render function. So I’ll just remove this. I’ll return render. And I’ll specify
the request function and then within a string I’ll specify
the HTML file which is present in the demo app. So demo app. / hi dot HTML,
which is the name of my file. Guys, please write the same name which you have given
to your file. I’ll run my server
again after this. So python -. P y run server. Let’s go back to our server
and see what happens. So as you can see
over here guys, the title has changed
from the default address to Eddie Rekha and my home page
now shows a message saying hi. So I hope everyone’s clear
with everything until now now, all I’m going to do is
go back to my HTML file and do some modifications
to create my own website. So now to create my own website. I’m just going to modify
this HTML page guys. If you’re done till here, you’ve been successful in creating a website
now all you have to do after this is specify
your Project Specific HTML code. Let me just show you
a few basic things that you can do
using HTML over here. So I hope everyone knows
some basics of HTML. Let me just change
the message from high to welcome to edu Rekha. Okay, I’ll just
specify the second line of my page to be some h2 tag
and a new message saying that this is my website. Let me save this
and rerun my server. I’ll just go back to my server
and I’ll reload the page. So as you can see over here, the H1 tag says welcome
to edu Rica and the second. H2 tag says this is my website. So this is how you can write
your own HTML code to your program guys. So now let me create some list
over here to create a list. I can either specify it
to be an ordered list or an unordered list
for order list. I’ll have to use ol tag
and for unordered list, I’ll have to use
the UL tag over here. I’ll be using the unordered list and within this list
I’ll specify the list elements. First element is Python
and the second element. I will give us
Java or something. Okay, let me save
this go back to my server and reload this page. So as you can see
over here guys, it has created
an unordered list over here. So now let me show y’all
how to create a table over here. So to create a table for your website you
can use the table tag. And specify whatever style you
want for your table in my case. I’ll just give the width to be. 50% and I’ll close this. So within the table you
can have the TR the th and the TD tags. The TR tag is actually for the table rows th is
for table headings and TD is for the table columns. I’ll just write a Dr. Tag over
here and within this TR tag, I’ll specify the th tags. Let me just give
the heading as python. And I’ll give another heading. as Java So after this, I’ll create another row
using the TR tag. And within this I’ll
specify the columns. So for that I’ll use the TD tag
and I’ll just specify which IDE you can use
for Python and Java so for python you
can use pycharm. Let me just copy this. And for Java you
can use Eclipse. So I’ll change the name from
pycharm to Eclipse over here. And I will save this. So as you can see over here
a table has been created but guys my table
over here does not have any borders to add
borders to my table. I’ll go back to my HTML page
and over here within head. I’m going to use the style tag. And within the stack
I’ll specify what border I want for my table. Let me save this
and reload my page. So as you can see
over here guys, I included the style tag and specified what kind
of Border I want. So the same way on my server over here
a table has been created with a specified style to know
more about HTML and learn how to create
beautiful websites. You can just go
to the bootstrap website. And from here you
can take any code that you want for your website. So I’ll just show you
what happens when you use this. So let me just use the style
from the bootstrap and it should be present
within the head. So I’ll just paste it over here. Let me save this. I’ll go back to my server
and I’ll reload this page as you can see over here guys using the small bit of code that was present
of the bootstrap website. My website looks so
much more better than what it was looking before this. You can use this bootstrap
website to create your own beautiful websites. Okay. So with this we come
towards the end of our project. So I hope you are clear with all that’s been covered
in this session. In case you have
any queries or suggestions, please do let me know
in the comment section and I will revert to you
at the earliest good bye and take care. I hope you have enjoyed
listening to this video. Please be kind enough to like it and you can comment any
of your doubts and queries and we will reply them at the Earliest do look out
for more videos in our playlist And subscribe to Edureka channel to learn more. Happy learning.

Author: Kevin Mason

Leave a Reply

Your email address will not be published. Required fields are marked *