Transcripts
1. Course introduction: Welcome to the best
course online, which will help you
learn Django by building real-world applications completely hands-on.
I'm Professor. I have created this course
to help developers like you gain confidence with
the Django framework. Why should you take this course? The goal of this
course is to make sure you learn Django the right way and don't waste any time going through broken,
incomplete online tutorials. In this course, I have simplified topics and made
it easy to understand. With real-world examples. I will make sure you not only
loan jangle the right way, but also have fun learning it. This is not a
theoretical course, but we will be
doing practicals by writing code and
building applications, which will help us understand each and every
concept even better. This course is designed
gaping pig nose in mind. We have material that
each and every concept is clearly explained in an
easy to understand manner. If you are a beginner,
don't worry, I'm 100% committed
to help you succeed. After completing this course, you will have a solid
understanding of Django framework. We will be doing some
real-world projects which will not only help you write complex web applications
confidently, but also crack job interviews. Why should you learn Django? Django is a Python-based web
development framework which is used for building highly
scalable web applications. Django encourages
rapid development and is very easy to use. It handles a lot of
configuration automatically so that developers can focus
on writing business logic. This helps developer save time and focus on
what's important. Django is used by many top
companies in the world. If you are serious about your cardio and becoming
a good developer, loading Django can actually open doors to some of the best
companies in the world. What are you waiting for? Let's take the first step. I'll see you inside
the class. Thank you.
2. Setting up python on mac: Hello guys, welcome back. In this lecture, we
are going to install and set up Python on
your Mac machine. By the end of this lecture, you will have a complete clarity on what are the different
steps that you need to take to install Phyton?
Let's get started. The first thing that you need
to do is you need to check if Python is already installed
on your machine on RNA. You can do that by running
this command button three, double hyphen version
on your dominant. If you have Python
already installed, you will see the version number being printed on the console. If you don't have any
Python version installed, then you won't see any output. Just run this command and check if Python is
already installed. If by ten is not installed, then we will go ahead and download the Python
installer first. In order to download
the Python installer, we will hear the
word to a browser and search for Python download. And we'll press enter. Now, once we hit endo, we will see this first
link download Python, which is on the website
python.org slash downloads. I click on this link. The
moment you click on this link, you will be taken to
this particular page. This is the download page of
the official Python website. Now, you'll see that it's asking me to download the latest
version for Mac OS. Now it has already identify
that I am on Mac machine, and hence it's deadly
suggesting me to download. You can click on this and download the installer
to your machine. You can also browse
through a specific release that if you want to install
any specific version, you can browse through. So there are different releases, but this is the latest version that you're seeing at the top. Downloading the installer from
you is highly recommended. Just click on this and get it
downloaded on your machine. Now once you have downloaded the installer on your machine, you have to double-click on it. And the moment you double-click, you will be presented with a screen which looks
something like this. Now, I'm not actually
going and installing Python on my machine because
I've already installed, but in screenshots on my system. So I'll be giving
you a walk-through. What are the different
screens that I saw? And what did I do on
each and every screen. You will see this
introduction screen. You can click on Continue
or were you okay? The moment you go on
to the next screen, you will see an option to
continue your as well. So this is the Read
More option, right? And you can read
more information about this particular software. You just hit Continue and you will be seeing the
licensing information. You have to hit
Continue with you. You can read the
license if you wish to. And you might also be
presented with a Agree button. You can hit I agree, and you can go to the next step. The next step it will ask you
for the installation type. It's not the installation
type exactly, but it's showing you the
installation information. It's telling you
how much space does particular installation
will take on your system. And it will install exactly. Right now, this software is installing on this
particular hard disk Macintosh HD might
let say if I don't want to install in
this particular disk, then you can click
on Change installed location and change
the destination. You can do that. I just hit Install. Alternatively, you can also
see the Customize button you. So this is the standard
installed that is happening. So you can see the standard installed that is
happening over you. If you click on Customize, you will represented
with this green. Now this screen allows
you to customize the components of Python that you want to install
on your system. You can check on takeaway you, but I would recommend to
do a standard installed. On the previous screen. You just click Install. Or if you've entered the screen, like clicking Customize, you can click on
standard installation. It will just install
the standard version of Python with all the required
tools that you need. Now hitting standard
install will ask you for your
system password. So if you have Touch ID
enabled or you have password, you can just enter
your system password. Once you know, you will
see this progress. Now this problem is that Python installation
is in progress. Okay, So the system
is installing Python. You will have to wait for
few minutes, not very long. After that discontinuing
button will be enabled. And you can hit Continue. The moment you hit Continue, you will see a somebody. And this four will open up the folder which contains all
the Python related fight. It just opens up and you can see the different files
that's been created. You can just close this folder or you can browse
through if you wish to. You can just close
this and then you'll have to check if the Python
is installed successfully. And to do that, you have
to run this command, python three hyphen,
hyphen version. Once you've done
this, you will see an output which looks
something like this. You will see this output and the installation
is successfully. When this video was recorded, 3.8 was diluted
version of Python. And I'm sure if you're watching it and when
the new version is out, it's pretty much that you will have the latest version
being printed over you. But don't worry, it's
just the version changes with some more phi2
and some bug fixes. So don't worry
about the version. If you're seeing a
different version, it's absolutely fine. Once you're seeing the
output on the terminal, you are done and you are
good to go to use Python. In this lecture, we
understood how can you install and set up Python
on your local machine. I hope you guys
enjoyed this class and found this class
super valuable. I shall see you guys soon. Thank you.
3. Installing python on windows: Hello guys, welcome back. In this lecture we
are going to start installing Python on
our Windows machine. And by the end of this lecture, you will have instance of Python up and running on
your Windows computer. So let us get started. In order to start the
installation process. First, we also need to check if Python is already
installed on our system. In order to check, we need
to run this command on our dominant Python three
hyphen, hyphen version. This command will print the version of Python if
it's already installed. And if it's not installed, it won't print anything
and show an error message. So I would request
you all to check if Python is already
installed on your system. If Python is not installed, we will go ahead and start the download process
when we will be downloading this particular
software from the Internet, and we would be then
installing it on our system. In order to download Python, we need to head over
to a browser and we need to search
for biotin download. Now once you hit
search on Google, you will be seeing this
particular search result which comes up waiting first. And this is the link of the official Python
website, python.org. And you are seeing the
download, my thin Martin. So you have to click on this and you are taken to
this particular webpage. At the top you're
seeing download the latest version
for Mac width. That's because I'm on
Mac and the website has identified that I'm on Mac and it's showcasing
that version. But if you're in Windows,
you will see windows. Were you with the Download
button at the bottom. And seeing this Windows
download installer, you have to just hit
Download button and download the installer for
Windows. If you scroll down. You can also download a specific release of
Python if you wish to. If you want to download
the latest one, you have to go from you. It's highly recommended
that you download the latest version of
Python from this button. Once you have downloaded
this particular installer, let's see what are the next
steps that you need to take. Once the installer
is downloaded, you need to double-click on
the installer and launch it. The moment you launch
the installer, you are going to see this particular screen wherein
you will be asked like, how do you want to
install Python? So you will be shown
this Install Now button. You can click on Install now to install Python with
default settings. Or you can choose customized to enable or disable features. If you hit Customize
installation, you will be asked to select which parts of
Python you want to install. We don't want to customize
the installation. We want a standard installation. Will be clicking on this
Install Now button. Just before hitting
installing malware didn't just make sure this is checked. So this will be checked by
default because it would be adding a lawn
tool to your menu. And also, we need
to check on this. We need to select Add Python 3.9 to plot this,
you need to do. Now, one important thing
I wanted to tell you is this is the installation
video for Python 3.9. This is recorded when
Python 3.9 most launched. But if you're seeing
any different version on the website and if
you've downloaded it, then the steps are the same. You don't need to worry about the difference in the steps. Because Python keeps releasing every version now and then. There are little
enhancements in some of the versions and
stability improvements. Don't worry about
the version number. You might see a
different version number if you are seeing this
video at a different time. But the installation
steps will be almost seem like they won't
default, they won't change. If they change, I'll make
sure I upload the video. So you have to just click on this checkbox or
were you alright? Once you click on this checkbox, so there's a cancel button, which I've just heard in myself so that you can see
the cancel button. You I'll just come back. There's a cancel button. So you just click on this, Add Python 3.92 part. You just hit Install. Now. Once you hit
Install Now you will see the installation process has started and it's
initializing now. So you'll have to wait for some time till this
progress finishes. Once this finishes, you will see the setup was successful. There's a button behind me, so I'll just hide for a while. The installation is successful. It's the confirmation pop-up and you have an option
to close so you can hit Close and disabled
or hide this baba, okay, So this was an
installation process. Once done, you have to check if Python was perfectly
installed on your system. In order to check this, you need to run this
particular command, python three hyphen,
hyphen version. This will tell you if the Python is installed properly
on your system. So you will see this version,
something like this. And if it's not installed, you will see an error message. That's about this class guys. In this lecture, we
understood how can you install and set up Python
on your Windows machine. I hope you guys
enjoyed this class and found this last valuable. I shall see you guys
soon. Thank you.
4. Setting up Atom on your machine: Hello guys, welcome back. In this lecture we are
going to talk about how can you set up
atom on your machine. And by the end of this lecture, you will have a clear understanding
of why should you use Atom and also how can you set this up on your
Windows or Mac machine? Let's get started. Before jumping on to the
installation process of atom, I would like to
discuss a few pointers on why you should
use an IDE first, we need to understand that. And after that we can headword
to atom installation. So why do you need an ID? So ID stands for Integrated
Development Environment, which is nothing
but it's a software which provides you an
environment for writing code. Now, there are lots
of benefits on why you should use an ID over
the normal text editor. You can also write code in
a normal texture though. But writing code in text
editor won't give you that. Productivity or an edge. Id makes sure that you have
all the tools you need. And it also improves your productivity and makes
your life much more easier. Let us understand how IID makes your life
much more easier. The first benefit of
using IDE is you get easy source code editing
by highlighting syntax. So you get to C syntax highlighting for
different keywords when you are using ID. If I have to give
you an example, here's an example of a Python code written in
a normal text editor. This is a normal text editor. You can see there is no
syntax highlighting for you. But this is another piece
of code written in an IDE. And as you can see that you're the class names to identify as the method names
are highlighted. So you're, if you
see the comments are also highlighted in green. Which really gives you
a really good feeling. And you can understand that
these are comments written. However, in a
normal text editor, you can see that comments are
appearing in a similar way, just like any other
line of code, there is literally
no functionality that is just raw text, but you feel better and it makes your life
much more easier. Another benefit of using an ID is this
auto-complete feature. If you're writing a
code in a text editor, you have to type
everything by yourself. But in IDE, you
have to just type a few characters and you will be given an auto suggestion
with the list, alright? And you can select from
the list on what are you trying to write in. And you can also see parameter
does information and all. This is an example of a print statement that
I'm writing using an IDE. You can see the ID understands, okay, I might want
to write in print. And it's also throwing
me the list of parameters that can go with
this particular method. It makes your life
much more easier as compared to a
normal text editor. So in a normal text editor, you might make a
lot more mistakes than using an ID textual data. You might use
incorrect parameters. You might make
spelling mistakes, but since you are
being auto suggested, you might just press
enter and move on. And half of the code is automatically written
in order generated. This is one of the important
benefits of using ID. The ID, whichever you use, also comes with a lot of
feature like easier debugging. Debugging is much
more easier in IDE. You can, like many, most of the IDs in the market have this feature
wherein you can attach a debugger to the
code and you can see where, on which line the error is. And this makes your
life much more easier as a programmer. Also, lot of IDs have version control features
which you can use. And if you're working in a team, this feature becomes
much more important, wherein you can see the different comments that
are being done by your team. And you can see what
are the changes your team is twin and more
to your team is working on. Id in short, makes your
life much more easier and makes you as a software
engineer much more productive. This is about ID. Now let's hop on to our browser
and let's download Atom, because Adam is the ID that
we are going to install. And we're going to set this
up on our system hardware to our browser window and on Google I'll just type
in Though, download. The moment I type
in item download, you will see this
first link, atom.io, and this is the ID that we
are going to use and install. So you can see this is the website and you can
see some of its features. Like it has teletype wherein you can work with
different developers, like some other developer, you can pair in and you
can do pair coding. You have good Hub integration, which is nothing but a
version control system. This is the world's most popular version control
system out there. And it has a very good
integration with GitHub. Then you have lots of features like smart
auto-completion. You have a built-in
package manager. If you want to add a lot more
capabilities to your ID, you have a system of packages. Packages are nothing
but plugins, which you can add into your ID. So let's say if I'm
working with Python and if I want to have
autocomplete feature, I have a plug-in for that. There are different
plug-ins available to add various functionalities
or what an above the base functionality
that you have. You have File System Roberto,
cross-platform entertain. You can set up multiple panes. You have features like find a place and a lot more things. So you can just go through this. And on the homepage I am seeing Mac and it's asking
me to download. Now I'm seeing macOS because
I am using a MacBook. I'm on Mac. And that's why
it's suggesting me macros because it has
identified automatically. If you are on Windows or Linux, you will see when
those being displayed and the appropriate
download button. Just hit Download and download the installer onto your system. In order to see the
installation steps, we will go to this
documentation link here. You can click on the
Documentation here. And you have flight manual, API reference and
atom discussions. So you have to click
on atom flight manual. Here you will see this is the entire manual
of the item ID. So we go to Installing Atom. And you have to do deal installation steps for
every operating system. You're at the top. You are seeing Mac is by
default selected. That's because I'm on Mac. Once you download the installer, you have to extract the
installation files. Once you've done that,
after extracting, you can then drag the atom application into
your applications folder. Download, extract that. Do we get from the website? You have to extract
it, unzip it, and then you have to track
the atom application that you received into the
applications folder and you are done with
the installation. Now when you first open atom, it will install Atom and it will run some
commands in the dominant. And once after you open item, you need to check and you need to be sure installation
process for successful whether item
is installed properly. For that, you need to run this command on the
terminal, which item? This will print the location
where the atom is installed. If you don't see an output
for this, like this. If you don't see an output
for this particular command, then it was not
installed properly. Ideally, you should
get this like once the installation
process is complete. This is on Mac,
it's pretty simple. You have to just drag drop the installer into the
applications folder. For Windows, I just switched
to Windows pane over here. And for Windows it's
also easy and similar. So you will get EXE file. It might really, the name
might vary depending on which platform you are
on, 32-bit or 64-bit. Now, you have to
just double-click on the installer and follow
the installation steps. That is it. Now once the
installation is done, you can launch atom. On Linux. If you're on Linux, you have commands for
different versions of Linux. So if you are on
Ubuntu or debit, you can execute these
set of commands or you like they've given
all these steps over you. You can just execute these
steps on your machine. If you are on some adult
Linux operating system like Red Hat or Fedora, you can run these
commands at the bottom. The institution guide is
pretty sorted for item. Now, heading over to
our presentation, once you launch the atom
for the first time, you will see or speech, which looks something like this. I saw this, but I have had instances where
you may have also seen the welcome screen. You might also see
a welcome screen or a welcome message,
like welcome to item. You can just close it. And this would be the full
speech that you will see. If you click on Add folders, you can add projects
onto your adam ID. This is about the
installation process and how you can set up an
item on your machine. So let's summarize. In this lecture, we'll be
understood how can you install, download and setup
atom on your Mac, Windows and Linux machine. So I hope you guys
enjoyed this class and found this last valuable. I shall see you guys soon. Thank you.
5. What is Django?: Hello guys, welcome back. In this lecture I'm going to
talk about what is Django. And by the end of this lecture, you are going to have a complete clarity
on what is Django. We're going to understand some
of the history of Django. We're also going
to understand who uses Django and some of the benefits of using
Django. I'm so excited. Let's get started. First, we're going
to discuss what is jangle, what does Django? Django is a high-level
web development framework which encourages rapid development and design of scalable web applications. And Django is very, very easy to use and saves
a lot of developers time. Django handles a lot of
configuration automatically so that developers can focus
on building applications. If you are using Django, there is very less
of configuration that you have to do as compared
to the traditional way. Django handles all the configurations
automatically by itself. Let's take a look at some
of the history of Django. Django was designed by
Lawrence Journal in 2003. And this started as
an internal project. And it was released in 2005 under one of the
license called BSD. As of today, there have
been several improvements in Django as compared
to the initial release, which was done way back in 2003. The current version of Django is very mature and has
tons of features. So we will be learning each and every feature as we pass
through our discourse. As of today, Django
is open source with the contributors
across the globe. There are lots of contributors
who contribute and have helped develop this
framework to what it is today. Django is completely
open-source and free to use. So anybody on the Internet
can download and use Django for building web
applications using Python. Now, since we have a clarity on the history and the
definition of Django, Let's see who uses Django. Django is used by some
multimedia companies out there. We have Pinterest,
Instagram, Udemy, essential, DoorDash,
Mozilla, and even more. So these are some of
the best companies that have been using Django. And some of their product
is powered by Django. And such big companies are
using it means there must be something for us to learn and something we
should learn and know about. Django is being used by a lot of popular companies out there. A lot of biggies, and
these are some of them. Now, let's talk about
the benefits of Django. So what would be the benefit of using Django in your software
development project? The first benefit
that I can think of is It's Python-based. Python is very easy to learn
as a programming language. It is known widely
and it is very easy for any new developer
to get started using Django, since it is based on Python, because it's very easy
to learn Python as well. There's a lot of lesser code
that you need to write as compared to other programming
languages for simple tasks. And since Biden is very
easy to get started, Django is also very
easy to get started. This is one of the
major plus points that it is based on Python. The next benefit we have
is it's open-source. Now, Django is an open
source framework, which means, what do we mean
by an open source framework? Open-source means anyone
on the Internet can freely download jangle and use it in their
software projects, whether it's commercial or
personal or for any use. And you can use Django without any development
costs in mold. The third benefit would
be rapid development. So Django is designed to
save developer's time. Django makes sure that
things are easy to use. And developers spend
a lot less time in traditional tasks
like configuration. And they spend a lot more
time and focus a lot more on building the code
logic of the application. And Django just takes away these traditional tasks
like configuration and all. It just configures
everything by itself. So that is very
less configuration in mold when you use Django. So that developers
can focus a lot more on the code logic
of the application. The fourth benefit I
would have is scalable. Django can scale quickly into a large application
depending on the need. And there are apps that have
been built using Django that serve over 400 million
loss uses concurrently. Django is very scalable. It's very easy to scale. So if you are
building a project or starting something
today, there is. And if it scales to
great heights tomorrow, then scaling your
application to handle larger traffic would be much more easier if you
are using Django. The next benefit we have
is the admin interface. With Django, you get an admin interface that
can be used by you. You can configure admin
interface by just adding a few lines of code
in a couple of files. And this is one of the
coolest feature of Django. So with the help of
admin interface, you can do a lot of
administrative tasks and you can manage all the admin related activities
in your application. In other places, you have to build an admin
interface from scratch. But in Django it's building and you just need to do some
configuration out there. There are more features, so Django has lots of features, like we see layout. It has water m, which is nothing
but which stands for Object Relational Mapper. It's one of the features
which converts models or something like you have models in your application
entities, a database. We learned about this as we
go throughout the course. Then you have something
called as URL routing, which is handled by Django. We have something called
as session handling. So if you are building apps that require session
to be maintained, alright, so like if
you are building login application
wherein you have to maintain a login session. If you're building an e-commerce
application wherein you need to save the
items in the card during a single
session with the use of all these things are
possible with Django, so you can handle session. You also have
multi-language support. So if you want to build
your application, solving multiple languages for, if you have users all
over the globe and if you wanted to make sure you
so multiple languages, that's even possible
with Django. In this way, Django
offers a lot of more features like MEC layout, ORM, URL, routing, session handling,
multi-language support, etc. These are some of the benefits, an overview of Django. So let's summarize. In this lecture, we
understood what is Django? Why should you use Django? And how django makes life
easier for developers? I hope you guys
enjoyed this class and found this class valuable. I shall see you guys soon. Thank you.
6. Setting up Django on your machine: Hello guys, welcome back. In this lecture we are
going to talk about how can you set up
Django on your machine. And by the end of this lecture, you are going to have
a complete clarity of the different tools
that we are going to need to setup Django. And we are also going to
see this process in action. If you're watching this lecture, I would recommend that
you do install and set up Django on your machine as you watch this
video along with me. So let's get started. So first we'll talk about
what all tools we're going to need to set up Django. So we will first be installing virtual environment
on our machine, and we will be setting up a virtual environment
on a machine. I'll explain why we need
a virtual environment. Then we'll be installing Django into that
virtual environment. Now the question that you might be thinking
is why do you need a virtual environment
like Why can't do install Django directly on your machine. So there are many reasons on why you need virtual
environment will be set up post the first reason is managing requirements
for different version. Now, what do I mean by this? So Python applications often use packages and modules that not come as a part of the standard library that you
would have on your machine. And applications will sometimes need a specific version
of the library. And also the application may require that a
particular bug has been fixed or application may be written using an older
version of the library. So if you have multiple applications
running on your system, they might be possibility that multiple applications might need different versions of
pipeline, alright? That is because a compatibility issues or they have
built using dietary. So this means that it
may not be possible for one biotin installation
on your system to meet the requirements
of every application. If application, for example, needs version 1 of a
particular module, but application B needs version
2 of a particular module. So you can have both
the modules are different versions installed
on your machine, right? There might be some conflict. Now you have to
install either 1 or 2. Now, this will make one
application running. One application won't be
able to run because you don't have that specific version installed on your machine. Now, this is where virtual environments
come into picture. So with the help of
virtual environment, you can manage requirements
for different versions. The next benefitted you have
of what your environment is, it provides an isolated,
self-contained environment. Let me explain that to you. So there was a problem that we've mentioned
in point number one. So wet in multiple
applications required different versions of
software to be run. Now what is the solution
to this problem? The solution for this problem is to create a virtual environment. Now what digital
environment is nothing but a self-contained directory
tree that contains vital installation for
that particular version of Python lists a number
of additional packages. Now, different applications can then use different
virtual environments. So this can help you
resolve the conflicts like we had when we discussed the point number one, isolated, self-contained environment
would be the need if you have similar situation wherein conflicts are
arising on your system. This is why we need
virtual environments. Now, another point that I
would like to mention you, Module environments,
it's very easy to manage the dependencies that
your applications need. So for example, if, let's say you are using
a particular library, and if application
a needs one motion of that library and application B needs another version
of the library. Notice maybe because of
the compatibility issues. If you have virtual
environments set, then you can have different versions of library installed in different
virtual environments. This could make sure,
like bodyA applications could run without
conflicting each other. And this makes your
life much more easier. And you can manage all
the dependencies in a very easy way without having much
conflicts on your system. These are few reasons on why virtual environment
is the need. Now, let me explain what
is a virtual environment. So you can see this
is your system, like consider this box as your
system and you have Python 2.2 and Django to install
on your main system. Now let's say you have
application one which needs Django 1.5 and item 2.3, what do you going to do
is you created a box. Now this box is nothing but TO self-contained
virtual environment. Alright, this is an
isolated environment wherein you can install
this version of Python, this version of Django, and you can run application
one in a very, very ECV. Then you have another
application. Let's see. So you can create another
virtual environment on the same system with different versions of
software is installed. You can see you have
Python 2.2 Django to install on that particular
virtual environment. And application to is using
that virtual environment. And then you can have one more example wherein
you can have one more app, which requires the latest
version of Django, Django three and byte and 3. Right now, Django three
is not the latest one. I believe multiple
motions have come in, but this is just an example
wherein your application for needs Django
tree for it to run. So this is what a virtual
environment is, right? I hope you guys have a
clarity now on why you need virtual environment and
how virtual environments solved the problem of conflicting packages and
conflicting versions on a siem system. Let's move on. We're going to talk about
installation steps. So I just switch
over to my terminal. Right? Now. We're going to
start steps one by one to make sure that we have Django and virtual environment
installing before we begin. Alright, so I will
just show you I am in one of the
directories called Django. So this is my command dominant. Now, if I type in PWD, it will tell me which directory I am in vitro media in depth, but you're going to Window middle and you
can go to the directory. Very new wish to cold and wet and you wish to install stuff. Since I'm a Mac, I'm
end-users vessel source code. And I've created a separate
directory called Django. All right, I have to now make sure that I have pip3 install. Pip three is one of the packages that you will get pre-installed with the latest version
of Python client in 3. If you have Python 3
installed on your system, you will have pip3 also
running on your system. And a way to check if p53
is installed on your system is running this command with
three hyphen hyphen version. And the version of pip three will be
printed on your console. Or also if you guys don't know how you can switch to a
particular directory, you can type in cd, two dots to go to the
beta and the victory. So since I wasn't Django, I typed in CD dot dot, and I moved to the Beta
indirective Django. Alright? If I have to go to a
particular directory, I can use cd and see Django, Django, and just
go good triangle. If I ls, it will
give me the list of all the files that exist
in this particular folder. But there are no
files as of now. I'll just clear the dominant. Alright, I've confirmed that I have pip3 version installed, and I'll just clear the
terminal by typing in clear. Now the both step over u is two. Install the virtual environment. Alright, so what I'm
going to do is I am going to see in this dielectric pip3, I'm going to say installed. And the command I'm going
to type is Pip eNB. So you can see this
on the slides. I haven't run this command
pip3 install pip eNB and you'll get the output
something like this. Whether it will do some
processing, it will download, it will collect what you'll environment than it will do
some installation steps. And then at the end you will
see successfully installed. This message is
important. Alright? I just go ahead and I'll
just run this command. Alright, The requirement
is already satisfied, so I have already installed
this particular software, and hence you are
seeing this message. But if it's not installed
on your machine, you should see this
entire thing over u. So I had taken the screenshot when I had installer
though, PIP eNB. And that is a screenshot
that I am presenting to you all should see this message successfully
installed at the end. Alright? Once PyPy and reason
stored, I'll just clear. Alright, now we need to
start installing Django. Installing Django, we need to first create a
virtual environment. So how do we create a
virtual environment? In order to create a
virtual environment, we need to create a directory. We have already
created the directory like we are in
Django dielectric. Now, I'll say lighten
three high phi1, M and V. And I love to specify the name of the virtual environment
that I wish to create. I'll say Django, course, eNB. And I'll press enter. So this is the command python
three hyphen m, Django. This name can be
anything like you can give any name
of your choice. Now after this
command is executed, you can just press
ls and you will see a directory is created now. Alright, so let's come on, list all the directory in
the current directory. Only files and pull
not only the detector. In fact, I can see this
particular directory is created. Now, we have successfully created a virtual environment
called Django course eNB. Once you have created
the virtual environment, we now need to activate it. So how do you activate
the virtual environment? You need to type
in this command. This command read
only book on Mac, unix and Linux
machines or Windows. I'll be giving you the
instructions shortly. On Mac, unix and Linux, you need to type and source. You need to specify the
virtual environment name. Alright, so I need to see
Django goes E and V slash. I need to see slash,
bin slash activate. And I'll press Enter. You can see the moment
I pressed enter. This particular coastal we'll
change to Django, goes eNB, which means that now
I have activated the virtual environment and I have entered that
virtual environment. So now whatever I'm going
to do will be within this virtual environment
and not on my system. I'll be making changes in this isolated,
self-contained environment. And not only system. This is how you can activate the virtual environment
on Mac, unix, or Linux if you're on Windows, that is a separate command, so you have to specify the
virtual environment name. So I'll just specify Django goes E and V. You need
to put in backslash. You need to see scripts
slash, activate dot back. You need to use this command and you just
need to press in NGO. Or even if you go to
this particular folder, if you go to this full load
on your file system, alright, there will be a scripts
folder node and they will be activated dot bad file under
it on your Windows machine. You can redirect to
this particular folder or using the Windows Explorer, and you can click on
Activate dot bat. And that'll make
sure that you have activated the virtual
environment, but it's advisable. Let you do this from
the command prompt. Alright, so if you dive
this particular command, this is a dot bat
script which will get executed this particular
prompt or you, the DOM node bronchi will change to the virtual environment URN. So this will be the confirmation that
your script has been executed successfully and you have entered the
virtual environment. Once you are into the virtual environment
and you have activated it, you will have to install pip three in the
virtual environment. So let's see whether
we have to be pre-installed in the
virtual environment. We have 53.2. Alright. Now we are going
to install Django. I'm going to say
pip3, install Django. And I'll press enter. You can see it's downloading Django. It's installing. It does successfully
installed Django. One thing to note is Django
has been installed in this particular virtual
environment that we created and not
on the system. All right. And we also seeing
and warning you that you are using motion going deep point-to-point three, but those are latest version. So you can upgrade. What I'll do is I'll
just copy this command. All right, Let's look among that it's suggesting and I'll just basis and they didn't
work on 1 second. Just alright. Successfully installed
pip Grundy one. Alright. Now if I type in the BIP, you'll see VR on
watching granny one. Just clear the screen so that
it looks much more cleaner. Now we have installed Django. We obliterated the pip three. Now we need to verify if Django has been
successfully installed. And to do that,
we're going to type in Django hyphen admin. And I'm going to press Enter. Now the moment you press, I know you're going to see all this. It combines. All right, so all these
suggested commands you're going to see after you
type in Django admin. And this tells you that Django has been
successfully installed. Just hit clear once again. Now once we have
January installed, we need to now
create the project. Alright. So before creating the project, I'll just check in
which directory I'm in, I'm in geodetic tree. All right, I'll just hit Clear and I'll use a command, Django, admin, see, start project, and give this a project name. So I'll say Django course. And then press Enter. This is the command that you need to use to create
the Django project. So January start project
and the project name, and we got an error. This is not a valid
project name, alright, so we can't use hyphen
in the project name. So I'll just remove this
hyphen and I'll press Enter. Now you can see the
command will successfully executed just typing
the command ls so that it lists all the files. And you can see Django
course directory is created. Oh, you know, what I'm
gonna do is I'm going to just navigate to
Django COS directory. All right. I'll just typing ls, so you have one directory and one file where
you are, right? We are in this
particular directory, the main project directory. Now what I'm going to do is
I'm going to start my soul. I'm going to type in
fightin three managed BY, and I'm going to say Run, so I'm going to press Enter. This is a command that
you can use to start the pie tin or the
Django, so I should say. So. If you wanted to see your
application in the browser, you have to make sure that
the server is up and running. We have successfully
started those silver, alright, and you're seeing the Django version
being printed W. So it's Django for 0.1
version is what we're using. Alright, and you can
see this message with you that our development solo, it started on this
particular URL. So you can copy this URL. This URL is hope
the local machine. This is localhost one to 7.1 and this is a wedding
not obligation is running. What I'm going to
do is I'm going to head over to a browser. I'm going to paste
this particular URL. This is a URL and I'm
going to hit Enter. You will see this welcome page, which is by default
available in Django. And whenever you run your
solo for the first time, this is what you're
going to see. It clearly tells you that the installation has
worked successfully. Congratulations. And this is the welcome page. All right, so we have
Django successfully installed on our system is where you're going
to see all the logs. Since I accessed the
application from the browser, we could see some logs
being printed to you, which we are going
to ignore for now. Alright. Now we have Django installed. We have all the Django, so we're up and running. We have the app we can
see in the browser. Now what I'm gonna
do is I'm going to hide a word to atom. And I'm going to open
the project folder. This is how atom will
look for the first time. Alright, and we need to add, start adding the folder. I'm going to click
on Add folders. I'm going to redirect to facile. So school, Django. And I'm going to select this
particular folder, you, this was the project that we created and this was
the environment. So I'll just select
this particular folio and just hit Open. Now, you can see we have
our project in atom. Now one more thing we
should do is we need to add the virtual environment
into our atom as value. And to do that, we're
going to go to atom. We're going to go
to Preferences. I'm going to go to install, and I'm going to search for
package called atom hyphen. Hyphen will chill in V. This is the package
that we need to install. This package is already
installed on my system. But if you don't
have it installed, I will request you
all to install this. Once you install, you're
going to see you, you know, virtual environment. This next will come after you install this
particular package. Now how do you bring your
virtual environment? Are you, in order to do that, you have to select the virtual
environment you are in. So I need to go to settings. In settings, you have
these two text fields. Under additional
virtual environment, I need to be Steyn, the part of the folder where I have installed
the virtual environment. All right, So I'll
just head over to our terminal and just get the pot wherein
I have installed. This is the plot wherein I have installed my virtual
environment. I'll just copy this, and I'll just paste this. Now once we have added
this particular folder, we'll click on no
virtual environment. You will see your virtual
environment appear over you. But if you haven't
configured the spot, if you click on this, you won't see any virtual
environment being gone. Figured. If you wanted to see this in this suggestion already, the system will return
an environment that we have just created. In order to do that, you need
to mention the bottle you, that this particular
plugin knows where it has to look for the
virtual environment that you are expecting. So what I'm gonna
do is I'm going to select this
virtual environment. And you will see this
conformation virtual environment changed with success. And once this is done, you'll see the
virtual environment being reflected with
you at the bottom. This is a good time.
Alright? So we have successfully switched or added the virtual
environment onto atom. Alright, so that's about
this particular class guys. So let me just give
you an overview of what we did in this particular class
and what all we learned. Let's summarize. In this lecture, we
understood how can you set up and install
Django on your system. We understood what is the significance of virtual
environments and why you should have
virtual environment is configured before
you install Django, we set up our own
virtual environment. We can either down which
we'll environment, and then we install Django into that
particular environment. We also executed
or we also started our Django soil and we saw our app running
live in our browser. Lastly, we configured virtual
environment into atom. I hope you guys
enjoyed this class and found this class very useful. I shall see you guys soon. Thank you.
7. Overview of Django: Hello guys, welcome back. In this lecture we are
going to talk about and we're going to do
an overview of Django. By the end of this lecture, you are going to have
a complete clarity on defy structure of ij Django project and
what is the significance of each and every
file in our project? So let's get started. We have for our development
server up and running. Now to stop our
development server, I'm going to show you how you
can stop it so you can just press control C on your machine. And what will happen is
the solo will be stopped. So you can see like what? So control C getting
printed over u. So I've just put my solver. We can check the version of Django that we have
installed a video like this. You can see we have
installed version 4.1. Alright, so now we're
going to head over to Adam and we have our project
open here in front of us. You can see we have
the main project Hill, which is nothing but
the Django course. Then we have a sub
folder which has the same name as that
of the main project. You have two other fights. One is db dot SQL lite three. The other file is
managed dot p-y. This db dot SQLite three is due database file that we
have along with our project. Or if you are going to use SQL lite three in your project. This is where all
the information is going to get stored, right? We have another fight.
Recall manage dot p-y. This file is nothing but a command line utility that
is available for our project. We can use this
particular file for running up projects,
running migrations, etc. If you notice, like in
order to run a salvo, we executed this
particular command, Python three, Manage PY run TO. And we did this from
our project directory. When we executed this
particular command. This command was using
managed or PY file, which you can see you,
you, whichever opened, it will have some
code written in, but you don't need to change or you are not supposed to
change anything in this file. This is the file that is
available by default. We were using this particular
file to start also, you can see this
command where you might entry managed BY run solo. In a similar way, you
can also run migrations. You can also make migrations. So python three managed BY make my edition
is the command. It will make migrations. Whenever you make any
changes in the database, we will have to make
migrations and that is when this command
comes helpful. You can also perform migrations using this particular file. You can say python3 managed PY migrate in this command will migrate all the changes
to the database. This is a very helpful
or utility file that is available
in our projects. And v will be using this particular 5929 whenever
we're working with Django. One important use case of this particular file
is to run our solver. You could see we ran our
servo and we could see Your Honor app hosted one of the ports on
our local machine. So this is about
managed taught BY. Then, if you expand this
particular for-loop, you have this particular folder. Under this, you're going
to see few more files. So you're going to
see settings or BY, let's talk about settings.py settings or BY is a Python file. It keeps tracks of all the configurations
for your project. All right, let me open
the centroid to you. You can see it has some code
already written for you. All right. You can see this is the settings
file for Django project. And this is generated when we executed this
particular command. And we executed this command
to start the project. And this is a version using
which it just generated. You can see some links to the documentation,
will you? Alright? And you can see some
code already written. Now you can see this
particular file has all the configuration, so it keeps tracks of all the installed apps that
we have in our project. We have apps like
vitamin OT sessions. All of these are
pre-installed apps that we have and we get along
with Django project. You can add more. If you wanted to
install more apps. If you create apps in future, you can add them over you. This file. We keep track of install
apps middleware. So you can see the
list of middlewares that we have in our project. You can also have a look at the configuration
for templates. Templates is something that
we'll be using when we want to show a web
interface to the user. And we want to have a static HTML along with
some dynamic content. That is when m blades
come into picture. So this is nothing
but the configuration for those templates. Then we have the
database configuration. In see, our project is pre-configured using
SQLite three database. And the database exists and the BSDI up in
this particular file, db dot SQLite three, which is nothing but this
is a base directory. And under the base directory
we have db dot SQLite three. So this is the database that we have got preconfigured with our project if you wanted to make any changes
in the configuration. So this is the default
configuration that you have. You're going to of course,
go and make changes. So let's say in
case of database, if you want to use Postgres SQL or if you don't
want to use SQLite three, you can get that
configured over you. You can just come in and you can add your own
configuration w. Now, if you store folder, you will have more
settings that you can see. This is nothing but a
settings fight which keeps track of all the configurations
for your Django project, like install labs, databases, middle vertical
configuration, etc. Then we have URLs dot p-y. This is another
important file which defines all the URLs that
exist in your application. You can see we have
this particular URL that exists in application. So it's not an app
and admin slash. And this is one of the UL
is that is already defined. And whatever you wanted to do, we want to define, you have to pass it to the
function or we don't. And you can see it's been assigned to you
already by items. You can add more, you otters, and you can add more
functionalities as well. So it doesn't bother. You wanted to start BY, then we have Ws GI dot b. Bye. This is another file. Once you're done building
your application, the next step would be to deploy your application and
hosted on Omeprazole. You would be building
your application locally, like we're doing right
now on a local machine. What do we actually, once
the application is better, do you have to host it
somewhere on the web? So Ws GI stands for Web
solo gateway interface, and it defines how web service interact
with your application. This particular file will
act as an interface with it. That is this file for. Then you have is ga dot p-y. Now is Jan stands for o synchronous solo
gateway interface, and it is now replacing WAS GI. All right, it works in
the same way as WAS GI. And it has some additional
functionalities as well. This is the upgraded version
you can see for WAS GUI. So this is another file that
you have in your project. This is about your
project structure, Django project structure and the files you get by default
in your Django project. So I'll just close all of this. All right, So that's
about this class guys. I hope you guys now have a fair understanding of what are the different fights that exist in your Django
project and what is the use of each anybody
file that you see. So I hope you guys
enjoyed this class and found this class while I
shall see you guys soon. Thank you.
8. Using terminal in atom: Hello guys, welcome back. In this lecture we are going
to talk about how can you configure dominant and use a
dominant within item, etc. So by the end of this lecture, you will have complete clarity on the steps in bold and how can you do it right on your machine and sweating.
Let's get started. So you can see your I am on my item dominant
and telling now we have been using a
separate terminal to get things done
around Django. Alright, now we have an option
menu we can use dominant within atom itself so
we don't need to switch windows and do tasks odor. We can just run all
the commands and write code within atom itself.
Now how do we do that? In order to do that,
you will have to go to the preferences. You, you have to pick an item preferences and you'll
have to click on install. You have to install a package. And the package
name is platform i, o dot IDE, sorry, hyphen IDE. I've been dominating. This is a package that has come up and this
is what you need to install in order to enable
dominant onto your system. Alright, this is already
installed on my machine, on my instance of atom, and hence, it's not showing
me to install icon view. You will see an installer icon
and you can just click on Install like this
added onto atom. You might have to restart item. Once you do that, you will see a plus icon
coming over you. This plus icon, you're
going to hover on this. It says new dominant. If I just click on
this and you can see an instance of
dominant appearing over, you know, this is our
dominant, which we can use. So you can see Aldebaran present working directory
that we are in. We can start running Django
commands from here itself. We don't need to switch
to an external dominant. Oem will switch over to atom. Now before we start running the command
where you are right, we need to first activate
the virtual environment. Alright, so you can see this is not in the
virtual environment, and we need to first activate
that in order to make sure that all the
commands that we run are being executed in the
virtual environment. For that, since I'm on Mac, I'm going to run source. I'm going to say django. All right, I need
to first go back one directory where our
virtual environment is. What I need to do is
I need to now type in source, Django course V&V. I need to say when and activate. Enter. And you can see I
have entered the dominant. I can type in PR as well. Now if you are on Windows, you will need to use
this particular command. So you need to type in
your virtual environment. What do we approach our
environment is that you need to type in backward slash and you need to type in this
and you need to place in the moment you press Endo, you're going to see the
virtual environment being activated. So this is how you can
do it for Windows. Once we have activated
the virtual environment, you can go to the
project directory, to the project directory,
and I'd say by 103 managed dot p-y runs. So I'll just run this. You can see our development
so is up and running. If I refresh this,
it's up and running. Now how do I type in
the command window? This is one instance of dominoes that you
are running within. Your soul is running right? Now if you have to
run more commands, you need to stop
your server and run. No. So that is one more
way in which you can keep your solid running as
well as execute commands. In order to do that, you need to create one more instance
of dominoes volume. So I'll just click on
this plus icon or you, now you can see we
have Bu instances. You do icons at the bottom left, and you're now I can
run any command I wish. So I'm in the project directory. I can say Django admin version. One more thing to
notice is we are not in the virtual environment. We need to again, go to the virtual
environment, Yoda as well. So I'll say 1 second. I'll just enter the
virtual environment. I'll say Django slash, bin slash activate. Alright. This is our second
terminal button. We can execute any
commands we want. We have two instance of
dominoes running now, and we can switch like this
in click on these icons on the bottom left
and we can switch. I would highly
recommend that you should get this
configured so that you don't have to switch
between multiple tabs. One way that I prefer
to code, if you Okay, switching windows, I think
that's perfectly fine. That's just a
preference that I have. That's about this class guys. So in this lecture we
understood how can you configure dominoes in atom? And how can you install package and do all
these settings? I hope you guys
enjoyed this class and found this class valuable. I shall see you guys soon. Thank you.
9. Apps in Django: Hello guys, welcome back. In this lecture, we are going
to discuss apps in jangle. By the end of this lecture, you are going to have
a complete clarity on what is this concept
of apps in Django. Why does this concept exists? And we're also going
to start creating applications and setting
it up in our project. Let's get started. What
are apps in Django? So anybody Django application has the concept of
project and apps. Now we're not neat. And what is the rule of each one of them? Projecting Django
is the collection of apps and configuration files. And an app is a web application that is designed to
do a specific thing. A Django project can have configuration files
and multiple apps. Each app is
responsible for doing certain things like
authenticating users, accepting payments
from users, etc. Every app is responsible for a part like authentication,
logging, signup. There might be multiple
apps in the project, depending on the
various functionality, intermediaries doesn't work. The concept of project
and app is in Django. Project is a collection of
apps and configuration files. And one Django project can
have multiple apps within it. Now, how do you create
an app in Django? For that, we are going
to headwear to Adam. We're going to just close
this particular tab. We're going to just
expand this a bit clear. Now, I'll start creating
an apple with you. So for creating an app, you need to be in the
project rubric tree. And you need to run a command. You need to see by
103, manage dot p-y. Start app. I'll call
this app as full-stack. Best, enter. The moment you run this command, you will see normal
put o, u bar. On the left-hand side. You'll see a folder is
automatically being created. Doesn't nothing but
an app that has been created in the root
directory of our project. And if you expand this
particular folder, you will see it has
its own set of fights. All right, now what
are these fights? These are radius files that we have within our application. So you'll have any dot p-y, which is nothing
but an empty file. And it is not to be mortified. It tends that the current
directory is a package. Extend MD5, and it tells that the current
directory is a package. Then we have more than dot p-y. This is another fighting
that we have over you. In Django, you have
models which define the structure of the database and how data is stored there. You can define the design, relationships, the
attributes, etc. All of the database tables, the columns, all of that. Alright? You can do that with the
help of models taught BY. Then you have another
file which is at main.py. And this slide is used to
register Django models in the admin panel from where
you can perform create, read, update, and delete
operations of the entities. Django has an admin
panel which is inbuilt, and you can configure
different models over there. Then we have test.py. This file allows you to write test code for
the web application. Then you have dot p-y. Views are defined in this particular file and
views on nothing but interfaces through which users interact with
Django application. All the views is
defined in the form of classes and they're defined
in this particular fights. These are the videos
files that we get along with the application
that we create. And apart from this, there is one more file
which is usually created, which is nothing but
a URL to start BY. So we usually create the auto insert BY within
the application FOR loop. So we have one of the main
project Q at the top. And then you have, you can create one
mole you honors or PVA using new file that will define all the URLs that we have within that
particular application. I'm dying particular file is not my default present
when we usually create it. This is about the application and the concept of apps
and projects in Django. In this lecture, we'll
be understood What is the concept of apps
and project in jangle. We also understood how can
you create your own app. And we also went through
the overview and the structure of different files that we have within the abduct. We agreed. I hope you guys
enjoyed this class and found this class valuable. I shall see you guys
soon. Thank you.
10. How does Django work: Hello guys, welcome back. In this lecture we
are going to talk about how does Django work. By the end of this lecture, you are going to have
a complete clarity on the internal
working of Django. And how does Django applications work and how does the
request move from the user entering the
URL in the browser to he's seeing the
information on the webpage. So let's get started. So how does Django? Django is our MVD
based framework and indent M stands for Model, We stands for view, and D stands for depend bleed. Now, what is model? So model is the
logical data structure behind the entire application. Then we have something
called as view, which contains nothing
but the business logic. Now, view is the
main functionality of the Django architecture. And this is where we
write the business logic, which is going to be
responsible for the request and response according
to the client input. Alright, now, when the
page is requested, Django creates an HTTP request
object and the view takes the request from the user and processes the data accordingly with the help of the models. The view is
responsible to present the data gathered from
the model to the user. This is nothing but
what a view is. It is responsible for taking the requests
from the user and processing the day down with
the help of models. Models. We discussed that it is the logical data structure
behind the application. And this data structure
is essentially represented in the
form of the PDPs. Now, database can be
any database like you can use SQL lite,
MySQL, or Postgres. Now then we have the template. The template is the
part that is used for representation of the HTML
pages only web browser. It works in a similar
way as in the MVC model. If you are aware of
Model-View-Controller model, templates handle
all the HTML CSS, and display the actual
information to the user. This is nothing but how
MVC framework works and model is MED
based springboard, but in N stands for model, V stands for view, and these times
for the pamphlet. Now let us understand
this a little bit more. So here I have created a diagram which represents
the flow of the information. And you can see we have a user and this user sends a request. So basically here in
Tulsa, you want to, and he wants to see our
particular information and he's trying to access
a particular application. This request is usually entered in the form of URL
to fetch the resource. This request is
received by Django. What Django does is Django
looks for the URL mapping, looks up for the URL mapping. So let's say if you have an application with the
URL slash employees, so this particular you
will list the list of all the employees user intos this particular
URL in the browser, for example, application
name.com slash employees, Django receives this request. This request is then looked up whether is there any
such you want to define. So there must be some new wanted to define slash employees like we discussed in
the URLs dot p-y. If there is a similar, you want to define
slash employees. It looks at for this
particular URL. And after this
particular URL is found, the corresponding view is fetched against this
particular URL. You have the views
defined over you. You will have view
corresponding to the URL. Django does is it fetches
this particular URL and it sees that this is mapped
to this particular view. Then it goes to views.py OU. And ideally you will have the definition of
that particular view. Django looks up for
this definition and it starts processing
the logic right. Now OEO in views.py, inside the view that Django
has fetched or there, you will have code
to interact with model and get the
required data from the database if your application involves interacting
with database. So if there is a
database involved, there might be some code
written within the view itself to fetch the
data from the database. And then this information is compiled and shared
back with the template. You can see here
we have the URL, then the view is fetched, and then data is fetched from the model and the
template is fetched, and then these two are combined. So these two are combined and the combination of the two
is presented to the user. All right, modelling
done walks with the B2B. So we have database will
yield behind the morning, which allows the model
to fetch the data. So this is how Django
works in the background. So this is the internal
working of how a request is processed from user in
bringing the URL bill, he sees the information. This is nothing but
how Django works. I hope you guys
enjoyed this class and found this class valuable. Let me summarize
this class for you. So in this lecture, we
understood how does Django walk. We understood this is
MVD based framework. We also took a look at
this concept of immunity wherein we discussed
reward is Model, View, then bleed framework and how does a request walks or
actually in Django within a user and dose or you want to in the
browser till the time he sees the complete information
on his or her browser. That's about this class, guys. I hope you guys enjoyed this class and found
this class valuable. I shall see you soon. Thank you.
11. URL mappings: Hello guys, welcome back. In this lecture we are going to understand you want
to do mappings. By the end of this lecture, you will have a
complete clarity on what odd URL mappings and
how does django handles URL. So let's get started. What is a URL and
how does it work? So before talking
about URL mapping, it's important that we
understand what a URL itself is and how
does a URL works. So U stands for Uniform
Resource Locator. So this is the full
form of the URL. And it is address that user in those in the browser to request for a
particular web page. You, you also must have, use several websites and expected particular web
page to load, right? So that is what you
want, is, for example, you might have ended google.com and expected
google.com to Lord, facebook.com, you must have entered an unexpected
Facebook to load. You want it is nothing
but something, an address that you enter into the browser and you would expect a particular
web page to load. Now how does Django handle URL? Django allows you to define URLs that the user would
end up in the browser. Developers can define the
URLs using the plot function. You have a path function
that exists in Django. And using this
particular function, you can define URLs. And this function as a link between an
element and the URL. Path function returns the
tuple of URL patterns type, which is then used by Django. So here is the syntax
of the function. So you can see there are
different parameters. As you can see, the one is root, view, KWL, gs, and
you have name. So you have these bowed
assigned to none. Let us understand what each
one of this is. We have root. So this allows you to define the URL that you wish to have. This is domain part. Then you have view. And here you specify the name of the view which this
URL is mapped. Every you must have a view
that is mapped to it so that it can show the expected result
and the view to the user. Then you have the
next two parameters. The next parameter is args
and quarks is used to pass a variable number of
arguments to the function and guanxi is used to define
keyword list of arguments. Then you have name
and name is used to assign a name to the
URL that you are defining. There might be scenarios wherein
you might want to define a particular name to a
URL that you've defined, then you can use that
name to refer the URL at different places in
the Django application. And that is what this name and I'm adult allows you to do. This is about syntax. So let us hop onto our
project right now, and let's create a URL to your, I am in our Django
project which we created. Here I have the app for loop, and this is our main
project folder. And under the main
project folder you have this file called
Joanna's dot PY. And you can see we have some commented code
like we discussed. And see if we have the
spot function which we'll discuss with you on slides. And you can see we had
full but I'm a dose. You have two
parameters defined you because not all
foods are mandatory, the last two are optional. This is the plot function, and then you have
the URL patterns. So by functions returns a
tuple of URL patterns type, and this is used by Django. Django looks up
for URL patterns. You can read some documentation. We'll URL Python, list
roots URL to views. And you can see some examples, those who have been
mentioned earlier. You can see this example. You, this is the
example of homepage, so it's empty, which
means it is the root URL. And your mapped it to a
view, views dot whom. And then you have named this
particular URL as home. Before doing this, you
had to import views. You have to import views because views is nothing
but a different file. Ou uses a different
file you can see. So do refer to home, you need to import views. We'll be seeing all
of this shortly. So this is the Project-based you want to learn, we would be creating
or you wanted to write down in our app
for low, basically, we need to create a URL in
the app folder first are, then we need to add that particular thing
within the mean, you want to dot PY file. What I'm going to do
with you is I'm going to create a new file. We're going to say new file. And I'm going to say you
want to start BY, okay? Alright, so we have, you ought to sort BY created. Now I'll go to
this URLs dot p-y. And I'll say, All right, Nothing part is empty. And coma, I'll say
include app, dot URL. This is what I'm going to
add OU and go to coma. And you are seeing an
error immediately. So our solver was running here. And you could see an
error immediately when you include is not defined. You need to import included and include the z part of
Django URL's package. I need to put comma, we'll, we already in boarding pot while include the include
function as well. Alright, so instead of w codes, I think I need to have a
single code like this. I'll save. So now you're seeing another
error on your console. So you are seeing, does
that other window, once we included this
include function. What we are doing we are
now is OB half created a separate us to exert PUI Phi for this
particular app for staff. We're telling Django
that also consider all the URLs that are defined in this
particular file, Yoyo, to say that we need to include the apps you
want to go pee way into the main project you
want to start BY Africa, including this, you will see an error again on the console. And the error says that this particular
file that we have, the URL to sort
BY under Falstaff does not appear to have
any patterns in it, so you already
patterns is missing. And that's because this
particular file is empty. So we need to define some code where we need to
write some code over you. And to do that, I'm going to just copy
this so we can copy. You added buttons from you. All right, I'll
just pasted here. And I'll remove this. We can remove this, we can remove this. We have you ought to
distort quite an MD. I will also have to add an import statement
to allow those inputs treatment we need to import pot because we are going to
use the plot function. Alright? Now those done so you can
see the error randomly, the moment we added
URL patterns over you. And we saved the file
automatically, randomly. Alright, so now we're
going to add o value. So I'm going to see bought. And you wanted to, we're going to see is hello, world map this you
want to do of view. I'm going to say views
dot hello, world. I'm going to name this you
want to as HelloWorld. We've done this and
now let me save this. Save, you will see
an error or you, it says name views
is not defined, so we are trying to
use views or you would we haven't
imported w. All right, so we need to say from
Dort in both views. All right, I will see you again. Now we're getting a
different better. We're getting an error saying Falstaff dot views has no
attribute, HelloWorld. And that's because we are
saying get helloworld from the views file might actually in views we don't have
helloworld defines, so that's the error
we're getting. We keep this as it is. Alright? This is intention. This is how you can
create or you want to and map it to
a view in Django. Alright, so let me try
accessing this URL no, and let me show you the output. So we have HelloWorld. This is a beach or
accessing HelloWorld. And you will see we
are getting an error. All right, no problem. So we are getting this error because the app is
throwing the error. If I try to access, let's say WW, it
won't load again. Alright, so let me comment
this chord for a while. Twin error. I'm wondering to show
you what happens if you try to access
or you ought to, which does not exist. If I refresh this, you will see, you'll get
an error for not full on. This URL is not yet defined. It's not defined because
we have defined it, but we have commented, alright, just
particularly you want it. But I'm just trying to show
you the error code or you. So there are different error
codes that exist with us. If you try to access
or if a user tries to access that does not
exist or is not defined, then you get a full naught fold. And full naught for the
item means page not found. There are different error codes, Like one is for naught full, then you have full nor three. Full NAD83 stands for
permission denied. If a user is trying to access something for which she does
not have the permission. So in that case, you will
see for nor three OU and the error message will
be permission denied. You have one more record as 500. So you can see 500 or you, and the error message
will be soluble adult. So if there is an
arrow at the syllabus, you will see that
particular error code. Then you have full naught for
which we are already seen. There is one motor
quarter quarter 400, which stands for bad request. You will see bad request
message with you. So bad liquids means though we are the parameters
that you've passed to access this particular
page is not valid or the parameters or something is wrong
with the request. And that's why it's
saying bad request. These are some of the error
codes that you should know. All right, I'll just remove this commented line
and I'll just hit Save. And the lenders
lecture on this error. In this lecture, we
understood what is a URL and how does
it work in Django. We also understood
how can you create your own URLs and map
it to a view in Django. I hope you guys
enjoyed this class and found this class valuable. I shall see you guys
soon. Thank you.
12. URL mappings: Hello guys, welcome back. In this lecture we are going to understand you wanted mappings. And by the end of this lecture, you will have a
complete clarity on what our URL mappings and how
those django handles URL. So let's get started. What is a URL and
how does it work? So before talking
about URL mapping, it's important that we
understand what a u itself is and how
does a URL works. So U stands for Uniform
Resource Locator. So this is the full
form of the URL. And it is address that user in those in the browser to request for a
particular web page. You, you also must have, use several websites and expected particular web
page to load, right? So that is what you
want is, for example, you might have
entered google.com and expected google.com
to Facebook.com, you must have entered an
unexpected Facebook to load. You want it is nothing
but something, an address that you enter into the browser and you would expect a particular
web page to load. Now how does Django handle URL? Django allows you to define URLs that the user would
end up in the browser. Developers can define the
URLs using the plot function. You have a path function
that exists in Django. And using this
particular function, you can define URLs. And this function as a
link between an element. And the URL. Function returns the tuple
of URL patterns type, which is then used by Django. So here is the syntax
of the function. So you can see there are
different parameters. As you can see, the one is root, view, KWL, gs, and
you have name. So you have these bowed
assigned to none. Let us understand what each
one of this is. We have root. So this allows you to define the URL that you wish to have. This is domain part. Then you have view. And here you specify the name of the view which this
URL is mapped. Every you must have a view
that is mapped to it so that it can show the expected result
and the view to the user. Then you have the
next two parameters. The next parameter is args
and quarks is used to pass a variable number of
arguments to the function and guanxi is used to define
keyword list of arguments. Then you have name
and name is used to assign a name to the
URL that you are defining. There might be scenarios wherein
you might want to define a particular name to a
URL that you've defined, then you can use that
name to refer the URL at different places in
the Django application. And that is what this name and I'm adult allows you to do. This is about syntax. So let us hop onto our
project right now, and let's create a URL to your, I am in our Django
project which we created. Here I have the app for loop, and this is our main
project folder. And under the main
project folder you have this file called
Joanna's dot PY. And you can see we have some commented code
like we discussed. And see if we have the
spot function which we discussed over you on slides. And you can see we had
full but I'm a dose. You have two
parameters defined you because not all
foods are mandatory, the last two are optional. This is the plot function, and then you have
the URL patterns. So by functions returns a
tuple of URL patterns type, and this is used by Django. Django looks up
for URL patterns. You can read some documentation. We'll URL Python, list
roots URL to views. And you can see some examples, those who have been
mentioned earlier. You can see this example. You, this is the
example of homepage, so it's empty, which
means it is the root URL. And your map it to a
view, views dot whom. And then you have named this
particular URL as home. Before doing this, you
had to import views. You have to import views because views is nothing
but a different file. Ou uses a different
file you can see. So do refer to home, you need to import views. We'll be seeing all
of this shortly. So this is the Project-based you want to learn, we would be creating
or you wanted to write down in our app
for low, basically, we need to create a URL
in the app folder first, and then we need to add that particular thing
within the mean, you want to dot PY file. What I'm going to do
with you is I'm going to create a new file. We're going to say new file, and I'm going to say you
want to start BY, okay? Alright, so we have, you ought to sort BY created. Now I'll go to
this URLs dot p-y. And I'll say, all right,
nothing is empty. And coma, I'll say
include app door. This is what I'm
going to add OU, and I'll go to coma. And you are seeing an
error immediately. So our solver was running here. And you could see an
error immediately when you include is not defined. You need to import included and include the z part of
Django URL's package. I need to put comma we'll
we already importing pot while include the include
function as well. Alright, so instead of w codes, I think I need to have a
single code like this safe. So now you're seeing another
error on your console. So you are seeing, does
that other window, once we included this
include function. What we are doing we are
now is OB half created a separate us to exert Dui Phi
for this particular app. First step, we're
telling Django that also consider all the URLs that are defined in this
particular file, Yoyo, to say that we need to include the apps you
already got p way into the main project
URLs to start BY Africa, including this, you will see an error again on the console. And the error says that this particular
file that we have, the URL sort BY under Falstaff does not appear to have
any patterns in it, so you already
patterns is missing. And that's because this
particular file is empty. So we need to define some code where we need to
write some code over you. And to do that, I'm going to just copy
this so we can copy. You added buttons from you. All right, I'll
just wasted here. And I'll remove this. We can remove this, we can remove this. We have you ought to
distort quite an MD. And I will also have to add an import statement to allow those inputs treatment
we need to import, but because we are going to use the plot function, alright, now those done so you can
see the error randomly, the moment we added
URL patterns over you. And we saved the file
automatically, randomly. Alright, so now we're
going to add o value. So I'm going to see bought. And you wanted to, we're going to see is hello, world map this you
want to do of view. I'm going to say views
dot hello, world. I'm going to name this you
want to as HelloWorld. We've done this and
now let me save this. Save, you will see
an error where it says name views is not defined. So we are trying to use views or you would we
haven't imported w. All right? So we need to say from
dark in both views. All right, I will see you again. Now we're getting a
different better. We're getting an error saying Falstaff dot views has no
attribute, HelloWorld. And that's because we are
saying get helloworld from the views file might actually in views we don't have
helloworld defines, so that's the error
we're getting. We keep this as it is. Alright? This is intention. This is how you can
create or you want to and map it to
a view in Django. Alright, so let me try accessing this you ought to know and let me show
you the output. So we have HelloWorld. This is a beach or
accessing HelloWorld. And you will see we
are getting an error. All right, no problem. So we are getting this error because the app is
throwing the error. If I try to access, let's say WW won't load again. All right, so let
me come in Discord for a while. Twitter. I'm wondering to show
you what happens if you tried to access
or you ought to, which does not exist? They finally finish this. You will see, you'll get
an error for not full on. This URL is not yet defined. It's not defined because
we have defined it, but we have commented, alright, just
particularly you want it. But I'm just trying to show
you the error code or you. So there are different error
codes that exist with us. If you try to access
or if a user tries to access that does not
exist or is not defined, then you get a full naught fold. And full naught for the
item means page not found. There are different error codes, Like one is for naught full, then you have full nor three. Full NAD83 stands for
permission denied. If a user is trying to access something for which she does
not have the permission. So in that case, you would
see for nor three OU and the error message will
be permission denied. You have one more record as 500. So you can see 500 or you, and the error message
will be soluble adult. So if there is an
arrow at the syllabus, you will see that
particular error code. Then you have full naught for
which we are already seen. There is one motor
quarter quarter 400, which stands for bad requests. So you will see bad
request message with you. So bad liquids means though, we are the parameters that
you've passed to access this particular
page is not valid or the parameters or something
is wrong with the request. And that's why it's
saying bad request. These are some of the error
codes that you should know. All right, I'll just
remove this commented line and I'll just hit Save and the lenders
lecture on this error. So in this lecture, we understood what is a URL and how does
it work in Django. We also understood
how can you create your own URLs and map
it to a view in Django. I hope you guys
enjoyed this class and found this class valuable. I shall see you guys soon. Thank you.
13. Views in Django: Hello guys, welcome back. In this lecture, we
are going to talk about views in Django. By the end of this lecture, you are going to have a
complete clarity on what our views and how can you create views in your
Django project? Let's get started. What our views? Views is the main functionality. Part of the Django architecture. View contains business logic, which is going to be
responsible for the request and response according
to the user's input. So let's understand
how can you define a view we have already
created or you want to heal? And particularly you want to is mapped to the view HelloWorld. Head onto views. Start BY. I'll start
creating a view over u. So I'll say def, hello world. Now, every view has
a pedometer request. This request parameter. And we also need to define
the function body on, right? So what I'm going to
do is I'm going to say written HTTP response. We need to return the object
of this HTTP response type. And this is something that
we need to also import. So I will say from Django
dot HTTP, HTTP response. All right, then I'll
see Hello World. And I'll hit Save. You can
see the error randomly. The moment I hit saved, the error when WE, and now the Django is asking you to navigate to this
particular URL. The app is successfully running. What do we do that with
you? So we created a view or you, hello world. Alright, and this view
was mapped to a URL, which is nothing but you ought to do is also
called HelloWorld. Helloworld function
accepts request as the parameter and every view we defined will take the request object as
default parameter. This is very important. And likewise, every view returns HTTP response object
that contains degenerated response which
you want to show to the user. So here we have a sample
response called HelloWorld. Alright, now let's head
over to the browser and let's try refreshing
this particular you want to. Earlier we were getting
full naught for. Now, let's refresh. You can see now we are getting HelloWorld and this HelloWorld
is coming in from here. I can also convert this
to one with exclamation. I can refresh it. You can see it's changing
as we change in the code. All right? Now, this
particular response can come from anywhere. So right now we have hard-coded
response, HelloWorld OU. You can have a response
coming in from the user. You have some dynamic video. The second video, you are
interacting with databases. You have some code redundant which interacts
with the database, fetches the information
and process it in HTTP response into the user. So you can have any responsible you and
getting a warrant to render or show to the user. You can show it from here. This is how you can create views and you can view
it in the browser. So that's about this class guys. I hope you guys
have afib clarity on board abuse and how
can you create views? In this lecture, we
understood what our views and we also created of you ve loaned that view requires
a request object which comes from
the HTTP package. And it also Niepce, sorry, request does not
come from a UDP package. Request is something that every view needs as
default parameter. And then you have
a UDP response, which is nothing but the
return type of the view. So every view needs to return an object of HTTP response type, which has to be imported from
Django load UDP package. And this responds is rendered in the browser and this is being seen by the user. I hope you guys
enjoyed this class and found this class valuable. I shall see you guys
soon. Thank you.
14. Django template language: Welcome back guys. In this lecture we are going to discuss Django
template language. By the end of this lecture, you are going to have
a complete clarity on what is Django
templating language. We will be discussing the need
for a templating language. And we will understand this with the help
of a demo as well. So let's get started. What
is Django template language? Html is used to define
static pages, however, will in real-world apps, you need to have an ability
to represent dynamic content. Now, what do I mean by dynamic content is
something that is changing. If you go to Amazon and you would see reviews being
changed everyday. For example, there might be
a product which might have full reviews pretty and
tomorrow if you go, it might have it reviews. This is an example
of dynamic content or it's not static,
but it's changing. Btl, which is nothing but dynamic template
language lets you define dynamic content and separate data from
data representation. Data representation
is nothing but HTML. Html is used to represent data wherein you
have some sort of formatting there and you render
the data in the browser. But if you want to define some dynamic content
inside the HTML, you don't have the ability
to do that right now. So static HTML does not
help you with that. But if you wanted to do that, you have something
called Ask them bleeding system,
which you can use. The Django has the Django
template language, DDL, which allows users to
build dynamic webpages. Let us understand what is a need for a
templating language. Html is a static webpage and it does not solve
dynamic content. Large-scale applications,
if you're building. That needs to be
an ability to push dynamic content into webpages. You can't just build a large-scale application
having old static pages. It has to be dynamic. Now, let me give you an example. If you go to Amazon and
search for UGA max, you will see this on
the beach. All right. Now this page has static HTML. So you can see this
all is HTML filters, Prime delivery,
shipping options. These are all HTML.
And then you have this particular thing when in
us seeing all the UGA Max, you have HTML which defines the structure
of the web page. You have this
product grid or Yo, which is defined, doesn't
define using HTML. But the content that you are
seeing is dynamic content. Today you are saying
this particular yoga mat coming first, the model you might see some
other Hugo might come in here as first because of
the change in rankings. So hence it's not static,
but it's changing. And also reviews pricing
everything is dynamic. So if the seller
changes the price, it will be reflected immediately
or you, it's dynamic. Reviews are also
changing forever. So for example, as of now, USC, 11 thousand reviews
approximately for this particular product. Tomorrow if you come, it might be increased
to 12 thousand. You don't know, right? It's dynamic. And all the information
that you are seeing or were you
like the delivery, like this free shipping
tag and everything. This is all dynamic
content that is static. Html is used to give a
structure to the web page. It has given a nice structure to this particular
webpage of Amazon. But it's solving
the dynamic content which is changing forever. All right? So if you have to build a large-scale
application like this, you need to have an ability
to solve dynamic content. In Django, you can create
HTML files and render them. You also have the
ability to define dynamic content in the
HTML file that you create. What changes if there is a change in the state
of the application. Like in this example, if there is a change in pricing, it will be reflected over you. The similar
functionality we have. If there is a change in the
state of the application, django allows you to
render that change. And this is done using
Django template language. With the help of DDL, you define HTML
templates which have dynamic and static
content boat and not rendered depending on the
street of the application. So this is nothing
but how Django helps you render dynamic
content with the help of DDL. Let us hop on to our IDE
atom where you are, right? And we are going to
do a hands-on demo. So in order to use DDL, we need to define templates. Let me tell you why you
need them boots as well. We have this view here which
was returning HelloWorld. Alright. Now let's say the one
hundred, five hundred to render some HTML or you would call them
building web pages. So I need to render HTML. How would you render
an HTML page, or you can write HTML street
over here, I can say h2. And I can see here like
this, and I'll hit Save. You can see we didn't
get any errors and hop over to the
browser and refresh. You can see this change to
heading to DAG, alright? So HTML rendering can be done within this attribute is
ponds, object or right? But tell me if this practical. It's not practical,
like HTML pages, if you're building a
large scale applications, you won't have a single
line of HTML code. You will have thousands and
thousands of lines of code. How would you define that OU? And this is where the
bleeding comes into picture. So here you can define templates
in your Django project. Alright, so let me show
you how you can do that. So we'll go to the
root directory or you hide everything else. In root directory, I
create a new folder, I'll call it m blades. And this is the page or this is the folder where all our
templates will be. My templates. I mean, HTML5, having
dynamic content. Now we haven't Development
know that we'll be writing all the templates in
this particular directory. But how does Django
know that it has to pick all the templates from
this particular directory. We need to tell jangle
that you need to pick all the templates
from this directory. And how do we tell that? We need to tell jangle using some configuration changes in
settings.py file redirect. You can see that is our
templates variable. We need to do some configuration
changes. Are you alright? I will do is here you have
this pedometer joke or D, c dot, dot, dot join. I'll see Bs, D-I-R. What we are doing is we are using this
function always dot, dot join, and we are telling Django
to join this base GIF coma emulates means the base
directory of the project, which is nothing but the
directory till Django course 1. Second, let me switch dominance. But if I type in this PWD, doesn't nothing but the base
directory of our project. And basically means
don't root directory in which your project exists. We are telling Django, like concatenate means
directly and templates. So though you want to become Django calls slash templates, and that is where
our template decide. But if you switch dominoes, the moment we saved
this file regarding an error saying name
OS is not defined. So we are trying to use a
function from OS package. Join is a function in OS
package which we need to import scar to the top, and I'll say Import. Hit Save. Run the solo again. You can see the error when WL. Now we have configured
the template spot. Now what do we need
to do is we need to start creating the template. I'll go to the
templates for loop. I'll right-click and
I'll say first dot HTML. And what I'll do is I'll
pay some sample HTML, OU, least as HTML, it's basic. So it has full-stack
application as the title. And under H2 it says, but you can do Django, hit Save. And now we have a template defined in this
particular folder. I'm going to do is I'm
going to go to views.py. Now the question is, are you returning the string
which had HTML quantity? You could also return a string with organ extremely quantum. How do you return a
page and how do you tell Django that render
this particular page? We now need to render
first dot HTML when a user requests slash hello
and when this view is called. How do you do that? For that, we'll have to comment this. All right, and we'll say return. Render. Render is a function
that we are going to use to render a template. And I'll say return the request object.
Yoda double-quotes. I'll specify the name of the
file, name of the template. And I'll save this. You can see we did not
get any error on right. Now, what are we going to
do is we can head over to a browser and we can
just hit refresh. And you can see full-stack
application is the middle ear. And welcome to Django
does is coming from. Then bleed. We have successfully
rendered or template. And it's an HTML template. It does not have the
dynamic content yet, but yes, we're slowly
getting there. This is a static template
that we are rendering. Now the question is, how do we render our
dynamic content and W? To make this dynamic, we need to pass dynamic
parameters to this template. How do we pass a
dynamic parameter? So in view here, we need to pass a
parameter like this. We need to open two curly braces and I need to specify
the parameter name. So I'm specifying name as
the name of the parameter. Specifying the value. We need to pass the parameter
in this format name. And the value of this
parameter is fightin. Now this pyramidal is dynamic and it can come from anywhere. As of now, I have hard-coded
this particular parameter. But this can be fetched
from the database. So you can have some
code which fetches the name from the database and it puts that
particular name or you, alright, you can do that. But as of now, we haven't reached
that stage yet. We haven't configured
database and all yet. But what we're doing is we're
hard-coding the content OU, and we are passing a
value so that we can get a just on how
dynamic content works. This parameter is dynamic
and can come from anywhere. All right, now, what
do we need to do is we have passed the
parameters successfully. Now in the HTML page, we need to take
this parameter and displayed to the user.
How do we do that? Instead of saying
welcome to Django, I'm going to put in
curly braces like this. So this is how you use a
variable in the template. And I'm going to see the
variable name over u. Variable name is name. Okay? That 40-year passing from you. And with the help of
two curly braces, I'm going to put in Nemo YOU. This pattern, like this way of specifying two curly braces, yielding HTML is known
as gingiva code. Gingiva G ING gingiva code. This Ginger code is used to render dynamic
content in HTML. I'm saying, welcome to static. And this particular
thing is dynamic. It will come from D Django
view. That is what I'm saying. And I won't all this thing, including this dynamic content
to be formatted as H12. This is the mix of the static and dynamic content that you are seeing over you. So if you had a war to
this particular page, all you get it as soon
as this is static. Get it as soon as. But Tuesday, 28
December is dynamic. It's coming from somewhere. So Amazon is calculating
this on the fly, depending on the current time. So when you search this
depending on the current time, it's calculating by when
it can ship and deliver this and get it as
soon as is static. And this particular thing is dynamic and it's
formatted in a way, it is tuned to the user. So that is what we are doing. What were you when you come to, does a dynamic
coming from Django and it might come from
database as well in future. But for now it's coming from Django and we're
formatting it into N2. Now, I'll save
this and let's hop onto our browser
and let's refresh. You can see it's in Python. And if I change all
your name to Tn, if I enter to n,
and if I refresh, you can see when for you. So this is how dynamic
content works with Django. I hope you guys have
affair clarity on how DDL works and how can you make it work in your Django project. So I hope you guys enjoyed this class and found
this class valuable. In this lecture, we
understood what is DDL? How can you define dynamic
content in your own project? We also understood why do
we need dynamic content and why there is a need
of having such a concept. But I think that is
fair clarity now. And I hope you guys enjoyed this class and
found it valuable. I shall see you guys soon. Thank you.
15. Achieving more with Atom: Hello guys, welcome back. So I wanted to create
this short lecture, could tell you about one more productivity thing, would Adam? I wanted to discuss a beautify login or
beautified package, which comes with item. So you need to go
to Adam preferences and you need to click on
Install and have atom hyphen. You define. If you type
in atom hyphen beautify, you will see this
particular plugin which you can install. This plugin, we'll beautify
your HTML CSS code. Alright, let me give
you an example. If you go to views.py, that is a possibility
that code might not be formatted in packages. Item beautify. You can see this Beauty
Pie option where you use the shortcut
for my machine. If you click on this,
I got an error. And the error was
it could not find a package called
ortho PEP eight. Alright, This was the package
that it couldn't find. So I Van Gogh my terminal. Alright, and I install, I ran this command, pip install. You can also run
pip3 install puppet, and I hit Enter. All right. It goes not installed. How did I check whether it was
installed or not? So I checked my
running this command. You can run this command, python three hyphen, md, hyphen. Wilson said, you can see
distractor is over here. It said that module
does not exist. What it is. I went ahead and I installed
this particular package. And after installing this, you can come to item, alright? You can see right now the
code is not well formatted. So what are you going to do
is you can go to beautify. You can see it's formatted now. So why according if your code is not well
formatted, it's not readable. You can use this
particular shortcut. You can buy hardness shortcut. Basically the shortcut on my
machine is Control Option B. That's the shortcut,
Control Option B for Mac. And you can check
for your machine. This is one productivity hack that I wanted to share
with you all the data. I hope you guys
enjoyed this class and found this class valuable. I shall see you guys
soon. Thank you.
16. Project 1 : Welcoming user with name: Hello guys, welcome back. In this lecture we are going
to create offers project. And the project is
welcoming useful. But his name. By the end of this lecture, you are going to
have this project already created on your machine. And while building this project, we will learn are tons
of things about Django and how can we use different
things in our project? Let's get started. This is what the project is. So you have a browser
wherein you will see a form and this HTML, maybe they're false dot HTML
uses it ended his name. Alright. He'll submit this
particular form. And on the other
page, welcome note, human user is shown
a welcome message. Alright, so the user is greeted. That's the project.
It's pretty simple. What do we really learn
a lot in this lecture? So let's get started. Who create this? We need to HTML files first dot HTML and
welcome to the HTML. False dot HTML will have a form wherein we will
ask for user's name. Then we will have
second HTML file, wherein we will welcome this particular
user with his name. Alright, so we need to pass name from one HTML file to the other. Let's get started. So let's
hop onto our project. You will open templates
for the starter HTML. Alright. Now will you create
a form under this body tag? I will start by writing a form. Form. We don't need to
define a class yet. We don't want define
an action yet. We don't want to
define a matured yet. And I would say is type in
some texts into your mean. And I'll have input field. This is all text and the
name of this field is user. On those scores mean
there's no value. We don't want any value
you as of now yet. Then we will have a line break. So we have Draco you. Okay? Then we will have
a submit button. I'll say input. Sorry, input. Type is submit. Just remove all of this
name and I reward value. I'll save this hardware to our project in the
browser and we'll refresh. You can see we have
full start HTML OU, which asks the
user for its name, along with the submit button. Now, when a user presses submit, we want to do some action. The action we will
define what is welcome. Now action is
nothing but the URL that we want the user
to be reductive too. And I'll just type in hello with you or I'll
say test that EMS best. Hit Submit. You can see we are
being redirected and it's just coming
onto the same page yet. I'll just save this. Refresh this again. Let me hit Submit. It redirected to the same base earlier because
this was not saved. What I did is I save the code, I refresh and I tried it again. So now, once we submitted our name regard
the full naught for error. This error says that Django is not able to
find this particular URL. So we are redirecting
the user to welcome because that's the action that
we have mentioned you. But Django framework does
not know what is welcome. And you can see the
editor, we'll, Okay. Gang were tried all
these URLs patterns but could not find. Welcome. Okay, now we need to go to
URL desert BY of the app. Within the app, we need
to do this URL to start BY toward add a coma with you. We need to create a mapping
you or where you come. So we need to see, but welcome. We need to define the view
file C uses equal to welcome. Really keep everything
10mers, welcome. Welcome. Run beautify. Rid of formatting, you're in debt and we have
the URL just created. Now you are getting
another editor. It says views does
not have welcome. We need to add view now. We'll head over to use dot p-y. I create overview. I'll say def accept request. Here. What I will do is I
will get the name. Here. We need to get the
name right now. We need to take the name. If you remember, user enters
a name on photo star HTML, we need to take the name and display it on
welcome dot HTML. So name needs to go from false dot HTML to
welcome to the HTML. What do we do is we have this request object has two pedometer with the help
of this request object. Really good the user's name. And now we'll create
a variable first, wouldn't say request
dot, get C, username. Username is coming
from the HTML file. So we have defined
the username here. You're getting this
username over u. Now we need to render. So I'll say return
render, request chroma. Let's see, Welcome HTML. I'll pass the
parameter name, colon. I'll say nim. We had hard-coded
content earlier, mature. Now we have our dynamic
content coming in. This is done. Now the thing is, let's hop over to a browser. Let's do a refresh. Let's type in a name, and let's do submit. Now we have another arrow so that you ought
to zeta is gone, which you are getting older. But the error now is we don't
have this template defined. Alright, so we add a
rendering this template, but this template
is not yet created. We will go ahead and we'll
create this template. Here. We have welcome dot
HTML and bleed created. And now are you. I am going to define some code which will
welcome the user. So I will see H12. And I'll say welcome. From here, we're passing this particular
parameter as name. So the name of this
phenomena is name, and that is what we are
referencing to. Wish you. All right. Now let's refresh this. You can see welcome best. Whatever name you
pass in from you. So if I say Java submit, you can see by income
Java John, submit it. You can see value component. Somewhere demo you pass in. You will be able to see that particular name
on Vikram dot HTML. Let me explain this flow once again so that
you guys are clear. So first we had a file
called Fullstack HTML, which is nothing but the page
that is loaded initially. And we have a form debt. We created two input type. One is the text field and another one is with
the submit button. Input type text. We have username and then
we have a submit button. Username is nothing but
the name of defeat. Once we hit Submit, this particular text is passed along with
the request object. First it goes to the URL lot BY, wherein it identifies the view. Once they view is identify, this particular
pyramidal username is fetched in the view and it's
assigned to a variable. And this variable
is then passed as a dynamic variable onto
the render function. Then we are entering
this particular HTML, welcome dot HTML. And we're fighting this meme and we're displaying
it to the user. So pretty easy How name went
from one HTML5 to another. It's pretty simple. And
we did it step-by-step. So in this lecture
we did assembled project when we welcomed
or users with his name. So I hope you guys enjoyed this class and found
this class valuable. We got a lot to
learn in this class. We understood how you
can use requests, how you can fetch
parameters and views, and how you can pass dynamic
parameters and see it in action being displayed
on the HTML templates. That's about this class, guys. I'll see you guys soon. Thank you.
17. GET vs POST request: Hello guys, welcome back. In this lecture,
we're going to talk about different types
of API requests. And by the end of this lecture, you are going to have a
complete understanding of what are the
different types of API requests that exist and what does each type
of API requests mean? So let's get started. Let's first talk
about different types of API requests that exist. So the first type
is a get request. Then we have something
called as post request, PUT request and delete request. Now let's talk about each
one of them individually. What is a GET request? A GET request is to retrieve or get resources
from the database. So GET requests are only used to read the data
and not change it. These are some of the
examples of GET requests. Get requests can be
used in a scenario wherein you want to
retrieve some information. So let's say if you
want to get a list of cities in the application, you can use a get request. If you wanted to get a
list of all the employees, you can use a get request. So you only getting the information and you
are not changing it. So you can use a get request whenever OR GET
request is successful, you will get the response, response code as 200. This is nothing but
all about GET request. If you hop onto the postmen, you will see a drop-down over u, which will show you
all the request types. You will see ghetto you. Whenever you execute
a GET request, you will see the
response code or you. So 200, OK, which means that the request
has been successful. This is about get requests. Then we have a post request. Now post request is used to create resources
in the database. So an example of
false requests would be creating a new employee. If you have a form
on your application and on clicking Submit, you want to create a new
resource like an employee. So you have to use post
requests on that button. If you have to create
a new resource, or post request will be used. And this is a response that you get if you're using
post request. So you get to 01, which is nothing but created. So if you are
creating something, you will use boosts request
and you will get to 01. Asked to response to 01 sees that that particular thing has
been successfully created, all you will get full naught
for not found PUT requests. Now PUT request
is used to update existing resources that
already exist in the database. So let's say if
you want to update the mobile number
of an employee, so you can use PUT request
in that particular case because the employee already
exists in the database. Now you just need to update
a property of that employee. You get response as 200, okay? If the request is successful, then you have something
called as delete request. Delete request is used to delete an already existing
resource on the server. For example, if you want to delete an employee
from the database, you will use a delete
request and the response on the successful execution of
delete request is 200. Okay? So these are some of
the requests types, get, post, PUT, and delete. You can use any of these
requests type depending on the scenario or the kind of operations that you
are willing to do. I hope you guys enjoyed this
class and found it valuable. I shall see you soon. Thank you.
18. Using POST request: Hello guys, welcome back. In this lecture we are
going to use post requests. By the end of this lecture, you will have a
complete clarity on how can you use post requests
in your project. Let's get started. I have my
server up and running and have already created
or project wherein we are welcoming or user
with the help of his name. Now, the thing that will do is if you notice the parameters
being passed in the US. If I go to this particular
page, Helloworld, okay. Whatever name I know, if John I submit, you see John is being
passed in the US. This is because it is being
sent as a GET request. Now what if I don't want the information that
I'm entering on one webpage to another, the past in the form of us. Because anybody can
read this right? Like I can read, you can read or
it can be hacked. Whatever you're passing some sensitive information
like passwords, urine, want that to
be passed in the US. But in that case, you will be using post requests. So as of now, we will using GET request. You're in full starter HTML. We don't have any methods
defined in the form. By default, it was
using GET request. Now how do we convert it to post your we need to add method. You can see that our default
two parameters with that you can put in two
values, GET and post. I'll put postwar you
and I'll hit Save. Now African murdered this
form to the post method. Now let's hop onto our browser. Let me refresh the application. Refreshed. Now let me type in test. Let me submit. For the moment you hit Submit, you
will see this error. Full node three, forwarded it phase CSRF verification
Introduction, feed request, a border. What is CSRF verification? Csrf is a type of attack and
Django go to whites or tag, which you have to use with
post requests to prevent it. If you're using post requests, you have to use a tag which is specific to this
particular attack. You can Google CSRF if you
haven't heard or to CSRF, CSRF and other window. So you can see it's stands for cross-site request
forgery attack. It's a type of attack
which hackers can do. Django already has
provided us with our DAG, which prevents this
kind of attack. You can read about this
attack if you want to. But for now, we will have to learn more on
how we can use to attack. What I'll do is I will
hop onto our ID Hill. I'll also show you if I can. Settings in settings
are not middleware tag. You will have this
CSRF middleware. Django has already taken care of this particular
type of attack. And it expects you use a particular tag if you
are using post requests, what I do is I go to form dot HTML hill under
the form tag, I'll have to write
some ginger code. Okay. I'll say same page
and I'll say CSRF. Just delete this so we have configured the
autocomplete plugin, so I'll just say CSRF and
I'll just press enter. So it just comes at. You don't need to type in Indian dev team. If you have forgotten the Django template
package in Adam, if you haven't, you can
type this by yourself. So we have entered the tag. This tag would make sure that
the set our goals of it. I'll just hit Save and we'll come over you and just
refresh this page. And I'll type in best. Submit. We have one more, I don't know. We are trying to fetch username. Alright, I got this error. So you're in this particular
line in the view. We're trying to get this particular name
with the get DAG. We need to change
it to post school. Were you in views.py? Here we are using this, get tagged to change
this to host. We'll now we have
switched to boast. Press back, refresh,
learned to John, submit. And you can see Viacom
john coming over you. And also you will observe
that the URL is clean now you don't see any pedometers
being passed in the US. It if you go to Google,
what do we use? Search is being passed
into pedometer. You, you can see Q
is equal to CSR. If my query is equal to CSR. And that's because
whenever you are searching is not as sensitive
information, right? So we will find with your search queries being
Boston as a GET request. But we know how we can
maybe get request. We also need to know how we can use bolster requests because whatever we are building
applications that might be more use of passwords. So that's where this comes in. That's about this class guys. I hope you guys have
affair clarity on what is post requests and
how can you make use of post requests
in your project? I hope you guys
enjoyed this class and found this class valuable. I shall see you guys soon. Thank you.
19. Installing required tools : Postgresql and Pgadmn: Hello guys, welcome back. In this lecture we are going to install the required
tools that we are going to need who start working with the databases and models. By the end of this lecture, you would have a clear
understanding of what other different
tools that we'll need. How are we going to
get them and how are we going to set them
up on our machine? So let's get started. So the two tools that
we're going to need is the postgres SQL
and the PG Admin. I would request you all to head over to Google
and your browser, and you need to search for
calls grit as good. Impulse. Great SQL download. This is what you need to search. And you will see the
false link over u, which is nothing but
the download link for this particular software. So I'll hit the world this particular link and
I'll open it in a new tab. You will see this particular
page of being opened. Now what is postgres SQL? So let me go to the homepage and let me show you
what was rescue ALS. As you can see on this particular
website, always great. Sql is a powerful open source object relational
database instructor. All right, so it's nothing
but a database system which is open source and
freely available to use. And we will be using this for our course and learning on
how to work with models. You'll have to click
on Download you, or you'll have to go to the download page which
you found on Google. On Download page, you
will see this section are your PostgresSQL download and under the CDC package
and installers, wherein you would be seeing the installer icons for
different operating system. So if you're on Mac OS, you can click on this one. You can go inside and you can install the interactive
installer by EDB. This thing is taller, didn't
need to install from here. You need to click over you and you need to get the installer. If you are on Windows. So you need to click
on the Windows icon. You need to download
the installer from you. If you're on Linux,
you need to click on Linux and select the
right operating system. For example, if you are
on Ubuntu and you need to follow the steps
mentioned over here. This is a process in
which you can get those Postgres as good
downloaded in your system. Now once you have
downloaded this particular are software
on your system, you will have an installer
and you will have to follow some
installation steps to get it setup on your machine. So let's discuss about what are the installation steps that are dead for this
particular software. The screenshots that
I have is for Mac. The installation steps on
Windows also will be similar, like installation
steps don't differ. And I've written
you're on Mac because the screenshots that
have taken is for Mac. So you don't need to worry if you are on Windows or Linux, the steps will
almost be similar. So if you click
on the installer, you will be seeing this
welcome screen or you, which you need to click Next on. After you click Next, you will be seeing
and you will be asked for the
installation directory. So I haven't changed the
installation directory. You I have kept it default
and I have pressed next. After you press Next, you will be asked for what components you
want to install. And you can select
the components that you wish to install. All will be checked. So I didn't do any changes here. I just clicked on Next. Then it will be asking you for the directory wherein you
would be storing your data. And this was the default
selection there. So I didn't do any changes. You're again, so I
just press Next. And then on this particular
screen you will be asked for a database
superuser password. You need to enter a
password over you. You can enter the
password of your choice, which you have to remember. This is a password that
we'll be using later on. Just make sure you
remember this or make a note of this
password somewhere. After entering the
password, Click Next. And after clicking Next, this would be the default port
where the soul would run. Suppose pre-filled, I
didn't do any changes here. But if you wish to learn database server on
some other port, you can change the
portfolio if you have something running
on the sport already. So I didn't have
anything on this port, so I just kept it default
and I just clicked Next. Again, I click Next, it was default locally
selected earlier. I didn't do any changes yet. Then it would begin the
installation process and it would ask for
the settings over here. So this would be the settings. And if you click Next. You will see the setup
is now ready to begin installing Postgres
on your computer. When you hit Next, you
will see the progress bar, which will do nothing but installed this particular
software on your system. You will have to
wait for a while. And then you will be seeing
the confirmation screen wherein you would be asked
if you want to launch. So I didn't check this. I didn't want to
launch tank below. It would be an
additional software that would be downloaded. I just hit Finish. Once you hit Finish, what
was great SQL installation. So this particular software
is now up and running on your system are right now you
have installed or database. So how would you go and make
changes in your database? Like how would you create
tables only create database. How would you view
all the data you need of view using which you can view all the database tables and all the information that you have stored
in the database. For that, we will be
needing BG Admin. So what is BG Admin? Pg admin is nothing but it's like a view for the database. Alright, so let me
show you how you can download and
install BG Admin. So I'll head over to
our browser again. On Google, I'll say
BG admin download. And I'll hit the
first link over you. And you can also go
to BG admin.org. If you go over you, you
will see BG Admin is the most popular and feature-rich open
source administration and development platform
for postgres SQL. It is nothing but an
interface using which you can administer and develop
things on the database. So here's what it looks like. A pretty neat interface, and it does the job really well, and it's open source. If you head over to
the download page, you can click on
download from here. Or you can click on
the first link volume. When you dive in BG admin
download only download page, you will see this
particular heading or your BG Admin full. This is the latest version
which is available right now. If you're watching this video later and if new
version is available, don't worry, you can
download the latest version. Okay. If there are any changes in the installation
steps and all, I'll make sure that I
update the video later on. So you can select the operating
system of your choice, whichever you are on. So if I am on Mac width,
I'll select macOS. And you'll see, I'll get a list of the versions
that are available. So I click the latest version. I would be presented
with the DMT file. So notice the DME file that I can download on the Mac with non EMG is nothing but the
installation file for macOS. And I just have to download
this and drag drop this onto the
Applications folder. I just need to follow
those steps there. On Mac. If you're on Windows, you need to select
Windows over you. It will open this
particular page and you need to select
the latest version. Then you need to download
the EXE install. Installation is pretty
straightforward. You just need to follow
the basic steps to install this particular software
and you would be done. Now coming back to
our presentation, when you launch BG Admin, after installation
for the first time, you will be asked for a master password that you
have to set for BG Admin. And this is something
that you're supposed to remember because this is something that we'll
be using every day. And just make sure you
make a note of this. You can enter the password of your choice and you
have to press. Okay. That was about the
installation steps, but if you open the pg admin, you can see its
interface like you have this database
stamp wherein you can see all the databases. You have this table tag
wherein you can see all the tables within
that particular database. You have some good absolutely. You, which show you
some database sessions, transactions, couples
in, doubles out, and this is some information
that you have you. Alright? We will be using this
interface to walk on the database postgres SQL that we have
installed previously. So that's about this class guys. I hope you guys have a fair
understanding on how you can get this software setup and
installed on your system. I hope you guys
enjoyed this class and found this class valuable. I shall see you very soon. Thank you.
20. What is ORM: Hello guys, welcome back. In this lecture we are going
to talk about watering. Now, what is the water? By the end of this lecture, we are going to have a complete gravity on
this concept of water. Why is it used? And what are the
benefits of using this? So let's get started. So what I'm stands for
object relational mapper. Now, every application that you are building has entities, and these entities
are represented in the form of classes
in your application. Like for example, employee would be a real-world entity if you're building an application
that is catering to employ of a
certain application. Now, employee would also have
some attributes like this. So you would have item
boots like employee ID, employee name and so on. You might want to represent this information in the database
so that it can persist. You have a class, it represents that
entity in real world. And you are going
to have a table which would represent this
entity in the database. Every class would have
attribute which would represent real-world
attributes like employee ID, employee name, and so on. You might want to represent this information
in the database. And this is represented
in the form of columns in the table that responding
to that particular entity. Let me explain this to you. You have this employee
class and then you can create multiple objects of this particular
employee class. For example, you can create employee one with
the employee ID, employee name and employee city, and it stores the information of this particular employee. Then you have the employee
to employee three. Now you have different
objects with different values to
these attributes. Now you might want to store all these employee information
into the database. What are you going
to do is this is how it's represented
in the database. You have an employee table in the database which
represents this glass. All the attributes of
this particular class go in as d column names. And all the values that you have assigned two different
objects going as rules. You have employee one object
as one row in the database. You can see Employee ID of John, an employee city and employee name of this
particular employer. And an employee T2
goes in as a rule, you employed three, goes in as a row or a record
you can see over here. So classes are mapped to tables, and objects are
mapped to records, and attributes are
mapped to columns. This is how the mapping of
glasses to database volts. Now, how do you manage
this in your application? So one way is you create a class and the developer
will make sure that he creates the
corresponding tables corresponding to this
particular class. And he also manages all the data that is
inserted and deleted. So if this particular
object is deleted, the programmer has to make sure it deletes the
corresponding record as well. This is being managed
manually. This is one way. Now in this manual approach, you have to write
a lot of queries and sometimes it
can lead to errors. And this is where one
m comes into picture. So the concept of ORM sees, whenever there is a class, that class is can be
automatically converted to a table along with it attribute being
converted to columns. Now the developer
does not have to write queries for TB creation, and it's created automatically. Whenever an object is created, it's data can be saved in the database as a
row in the table. This is automatically
handled by the water. This thing of converting the entire class to a table
is entirely managed by water. One M as a concept makes
developer's life very, very easy and lets the
developer focus on the application logic rather than focusing on
the SQL queries. It also minimizes
the mistakes since developers are not writing
queries on their own. So lots of mistakes
which usually developers might
make are reduced. One thing I would
like to mention is this concept of what m is
not specific to Django, but this concept
is also applicable to other object-oriented
programming languages like Java. It's also being used there. So this is about one
m and how it helps developers and how it
simplifies your process. Let summarize. In this lecture, we
understood what is water and how water works. We also understood
what are the benefits that what m gives us. I hope you guys
enjoyed this class and found this class valuable. I shall see you guys soon. Thank you.
21. What are models and doing database configu: Hello guys, welcome back. In this lecture we are going to talk about what our models, and we would be doing some
database configurations. So by the end of this lecture, you will have a clear
understanding of what our models and we would be creating a new app and
we will be setting up that app to work
with our database. So let's get started. What is a mortal? Some modelling Django
is nothing but a glass which can be
saved into the database. So every mortar represent
the table in the database with its properties being converted to columns.
Like we discussed. We have an employee class. This employee class is nothing
but a real-world entity and create different
objects of this entity. So we have employee one, employer and employee three. A video object has different
values for the attributes. So you can see different
values over you. Eventually the goal would be to save this information
in the database. So we can see all of this
information in the database. What happens actually is the glass is
converted into table. The objects are
converted into records and the attributes are
converted into columns. And a model is a class that can be
saved into the database. So since we want to save this entire class into
the DDB structure, that is what a
model is employed. Glass is a model
year in our example, and it is getting
mapped as a table. And all the parameters
are all the properties, I'm sorry, is being
converted into columns. So let's hop onto our Django project and
let's configure an app, work with the database. What we're going to
do is we're going to switch over to Adam. I'm going to open
the terminal or you. So in order to open a terminal, you need to click
on the plus icon. You knew dominant. What if you have the dominant
open, you can use that. But I had closed the
incidence of atom you. So I'll open the dominant. To start with, I'll
first create a new map. So we will be doing all
these configurations in the new app that we created. And I run this command to create a new app
by 103 Manage PY. And I'll say start app, alcohol the app as second nap. And I'll press Enter. Now the moment I press enter, you will see that we have this second app
created over you. Now, we need to configure this particular app
to work with the database. But before that, we will need
to create a database first. What do we are going
to do is we are going to head toward to a PG Admin and we're going
to create a new database. So we're going to see, we're going to say new table. Sorry, not new table, but we have on default
database available you. We will click on this database
thing. Where were you? And I will say create database. I'll call this database
as second app. We need to specify
the database anemia. Alright, I'll hit Save. Now the moment you hit Save, you will see this
information being populated. You can collapse
this and you have some default list of
tables here under schema. Alright, so you don't
have any tables created. New database won't
have anything. It's an empty database
that is being created. So now what do we have we're
gonna do is we're going to head over to Adam. We are going to
collapse everything. I'll just collapse everything. I'll just close everything. And I'll just open the second app over
you within seconds. Not the second
app, but I'll open the mean project FOR loop. Okay, So this is the main
project folder, Django course. And I'll open settings.py. Will you? Alright, now we need to
configure the database you, if you scroll down, you will see we have one field
called database for you. Alright? So this is a field that quantity goes
to dW is for us. What we're going
to do is there are some parameters that we
need to change over u. So we have this database stack. We have default tag and under
default tag we have engine. For now, we have the engine
define that SQL like. So now what is the engine Tank? Engine tag is nothing but the engine that we
are going to use to etch WASD connection between that application
and the database. So as of now we are using
the SQLite three engine to connect with the
SQLite three database. We will have to change this to work with Paul's great SQL. So I'm just going to replace this with this
particular string view. Django dot db dot backends,
dot postgres, SQL. Now we have to specify
the name of the database. So we are referring to the
root directory of the project. Here. We are not going to
use this database, so we would change
this to second. Now, there are few
more parameters that we need to specify in order to configure postgres
SQL with Django out. So we need to specify user. And this is something that you set during
the installation. So during the installation,
if you remember, on one of these screens you have specified the user
and the password. So I enter that user. Will you post, Chris? So my user is Postgres
and next parameter. So you have to make sure that
you enter a comma with you. And you have to put in the next paradigm
adult as possible. The parameter which is 1234. My password when I
created the database or when I installed this
particular thing, postgres SQL, there
was a password fee. So I had entered the
password as 1234. I had kept it simple. What is your password that you've had sent during
the installation? You have to make sure you
mentioned that over you. I've specified the
password as well. There are two more
parameters, like a host. And then you have to
specify another host. You need to specify where
your database is existing. So sometimes database might
be on different machines, and hence, this field is
important to be specified. But in our case, the database is existing on the same machine
as debt off ours. We are going to specify the
IP address of the local host. So it's one to seven
dot 00 dot dot one. If you remember, during
the installation process, we had specified the pool. There was a boat that
we had mentioned, so we will mention 5432. Okay. So these are the
configuration parameters that we need to set up for you. And I'll save this. Okay? Does this done? So if you have
configured the database, now, for database to work, we will need a database adapter. And your DAW's adapt TO that
we're going to use is cycle. So what I will be doing
is I will have to go to a browser and we will
have to type in cycle. I think. I'll go with you. Does this cycle and these are the instructions on how
you can install it. We will have to install this
in the virtual machine. We have to make sure that we are not yet connected to
the virtual environment. So just getting to the
virtual environment. So we add in the
virtual environment, no atom is for typing, terminal is not there in
the virtual environment. So we need to go into the virtual environment and
we need to activate it. I'll just go one step behind. And I'll activate the
virtual environment. Do activity with
children moment on Mac. I'm going to type in
the command as source and children Waterman name is Django course when we
bin slash activate. Alright, so I'm
chilling Waterman now and I'll head over
to Django course. Now I'm going to install cycle. So I didn't copy the command U and I'm going
to paste the command you. All right. So cycle will take or YE to get installed
on your machine, will read until the
installation is complete. I see some error where you cycle when solution
did not work for me. So I tried installing
a couple login, but then I got an error
that was not installed. I executed this command. You can see the command
on my dominant executed this command pip install really
started installing this. So this is one of
the dependencies that psychopathy might
need and you might get an error that the cycle is not able to install
because it cannot find. So just install this. But even after installing this
cycle did not work for me. It might work for you, but
it did not work for me. What I did is I went
to the documentation, you know, instead of
installing cycle, I installed cycle binary. So this is one motor or dependency provided by
this particular package. And you're going
to install this if you're not able
to install cycle, I installed binary and as
you can see on my system, it has successfully, you can see it is successfully
installed cycle binary. We are done with the database
adapter installation. Now, That's about the
configuration part. So we did a couple of things. You understood what is model. And we also configured the database and we also created a second app in our project. I hope you guys enjoyed
this class and found this class valuable. I
shall see you guys soon. Thank you.
22. Create models and run migrations: Hello guys, welcome back. In this lecture, we are going to start creating our models. And we are also going to
check if our configuration has been done properly
with respect to the database configurations
that we have done. And we're going to do something
called as migrations. So let's get started. First, we will check if T configuration that we have
done is set up correctly. So to check that we will
be running our Sobel. My soul, I mean the
biotin Django server. If the server run successfully, then like the configuration has been done properly and V are able to connect
to the database. So what I'm going to
do is I'm going to run the command to run. So I'm going to say by 103, managed BY and run Silva
Center, I get an error. So the error says second
app is not defined. So we didn't want mistake. We haven't specified the
single quotes over here. So I'll specify that hit Save. Then I'll run this over again. You can see y is up
and running now and the database connection has
been successfully done. Now, the next step is to
start creating models. So what we're going to do is we are going to create or
employing more than, which will have
three attributes. Firstname, LastName, and each. And then we will be converting this employee module
into a table. And the corresponding
properties of the employee class will be
converted into columns. So we're going to do
that entire process, and we will be doing
this entire process with the help of migrations. Now, the first step is we
need to create the models. What we are going to do
is VR going to go to second app and we're
going to go to models.py. We are going to create
a class employee. I'm going to say glass employee. I need to specify
models, dot model. We have done this and in
order to create a model and make sure that the
glass is saved as a table. We need to add this as the
parameter model, Stuart model. But you will get an
error if I hit Save. Okay, so we're not
getting any editor because this is
already imported. So I wanted to say that
we need to import this. What this is already important. What are we going
to do is we are now going to start
defining the fields. Fields you're going to have is FirstName, LastName, and each. But before defining field, I wanted to take
a moment to talk about something called
as Django model fits. So we know that every attribute in the class is supposed to be
converted into column, but every column in the
database hazard tight. What should be the type of
FirstName if you are creating? So that is something defined
by Django model fields. So I'll just take a pause and
I'll just go to Google OU. And I'll just say
jangle model fields. And I'll just click
the first link that comes off the official
documentation. This is nothing
but the list of or Django model field is something
that you'll find here. So you can see three types. You have auto field. This field is something, it's an integer field that automatically increments
according to the IDs. Then you have big autofill,
bigger digital field, binary failure Boolean.
You have Garfield. So cat is nothing
but a string field. If you wanted to store
or if you want to create a field which towards
character strings, then you'll need to use this. There are different
views that are available in this
official documentation. You can go through
this so you have various abilities
like float feed, image also you can
see it in the DDB. You have indeed your field
JSON feed a lot of fields, your time field, you can see if time you want to do as well. Decimals as well,
datetime as well, email as well, and file as well. So lots of stuff here. You can go and explore it. We would be using two types. One is the character field. This would be for the
first name and last name. So we'll be using
this character field. Then we would be using something called as
integer freedom. Indeed, you're familiar. This is something that we'll
be using for each, we will be creating FirstName, LastName, and each
for the employee. So we'll head over
to the ID at home. What were you? And I'll say first
underscore name is equal to models dot Garfield. And I'll have to also specify w. So I can say
max underscore length. So this is nothing but
the pedometer that I'm specifying using which
the restriction, so it'd be applicable to this particular column that
is created in the database. If you go look at a field, you will see you can specify the maxilla and
this is required. This is a mandatory field. This specifies the
maximum length of the characters in the field. Maxlength is enforced at the database level and
in Django is validation. What do you specify
what the value will also be taken at
the database level? And the columns that are created will be created
with this restriction, we have created this. I will duplicate this and
also create lastname. Okay? And then I let go and create
each is equal to models. Integer field. This is done. I've created the model. We have three fields,
firstName, lastName, and h. I'll just show you
about the digital field. So this is the description
of integer field. There is no
compensating parameter that you have to specify. All right, so I'll just close this search bar and
we'll head over to the IT. So we have something called
as mortals configured. Now if you remember, we created the app
and we haven't added this app into
our settings anymore. We could hear it an app. We need to add this app into settings. So I'll see second app, are you alright, I'll hit Save. Say second app is non-defined, reported in single quotes, alert, save and run. The solver. Can see the silver is up and running. This is done. We have created the
models and we're able to define the fields
within the model that we want to be
mapped to the database. Now the next step is to get these changes done
in the database. So if you take a look
at the database IO, there is nothing new,
nothing created. You have the Security
tab which you can use if you wish to or
I won't be using, but you don't have any D,
but you can use video. What do we need to do
is we need to propagate these changes in our
app onto the database. And how do we do this? So a way to do this is with the help of something
called Les migrations. What am I conditions? So migrations in Django, nothing but Django is way
off propagating changes did you do to your model into
your database schema? And these are automatic so you don't have to
do any manual ETO, but you have to make the migrations manually
and you have to run them. They might be some problems
at times that you might run into when those
are very rare. So whatever you do is I will switch over
to our domino now. I'm on the terminal, you and I am right now in the virtual
environment as well. Whatever to do with you is I
will create the migration. In order to create
the migration, I will type in the command. Command is by 103, managed BY make migrations. And I will address, and the moment you press Enter, you will see
something like this. Like the migration is
created under this folder. Second app, migration slash 001. And you shouldn't
be by, you will see a message on what
the changes will. The change was to
create model employee. Let me take you to this
folder, your migrations. And you can see zeros and a
one and you shouldn't be y. So this is a forced migration
that we have created. This is automatically generated. You can see the
date and timestamp. You can see this is all
auto-generated code. And you can see this is what would happen if
you run the migration. So a model will be
created in the database with the name employee and
with these economic dose. So there is a default field
that is added called ID. It is a big auto field and it's set to auto-increment,
I believe, yes. Auto created through
primary keep Drew and bullets named lastname, age with our restrictions, you can see now we have
made the migrations. If you can see the
migration from here, or you can also see them
aggregation using the command. So you can see by 103, you can see manage dot p-y, SQL migrate. Second app. This is a command python3
managed BY SQL migrate. You have to specify the
app name space, triple 01. Triple 01 because
that's the initial of the Migration Center. You can see this is our
migration and this is the query that will be executed once we
run this migration. If you wanted to see the
query part of the migration, you can run this command
and see you do yourself. All right, You can take this gradient also
executed yourselves, but we don't want to do
that if you wanted to go in the automated way. Now, we are done with
viewing the migration. Alright, now we need
to run the migration. So how we will run
it as Python three, manage BY, will say
My great presenter. You can see there was a set
of operations that happen. So I'll just explain this a bit. You can have a bit of
visibility so you could see applying all my conditions. So there was some default
labels that are created. Our domain OT content type, second lab sessions, etc. And you can see everything was okay. They wouldn't let us. Now, we'll head over
to the database. Refresh or William. The moment due to
refresh, you will see all the tables coming
out the way you. So you can see that has some default tables
like OTG group, permissions or destabilize
tools to user information. You can see this is the
table that got created. It's the employee
table and human notice that it is prepended
with the app name. So second nap
underscore employee, the model that you had
created what's called employ more than two table is app
name underscore employee. Okay. So you can click on
this right-click and you can go to View 1 second. You can view the
data. See you all to do w. So the w will be empty. But you can see the
fields over your ID. It's the big indigent. Then we have firstName. And you can see a
100 is the limit, last name, a 100 is the limit, and each is indeed you. So let's call our characters. This one is, we can teach it. You can see how our class got mapped into
a corresponding table, you into the abyss. And everything was automated
except the fact that you had to run one command to
create the migration. And you had to run
another command to migrate those migrations
into the 3D bees. So it's a pretty
automated process. It's just that developers has to take charge
on when during the migration and went
to make the migrations. So it's up to the developers, but it's an automated process. You don't have to deal
with SQL queries. That's about this class guys. So in this lecture, we
completed a lot of things. So we first discussed about
how can we create models. We created the models, we understood the model fields, then we even started the server and check whether our database
configuration was correct. We found some issues
there, we dissolve them. Then we actually
created a model and we learned what our migrations and we actually migrated
our models on to the database. Lot of learning. I hope you guys
enjoyed this class and found this class valuable. I shall see you very
soon. Thank you.
23. Django admin interface: Hello guys, welcome back. In this lecture we
are going to talk about Django admin interface. And by the end of this lecture, you are going to have a complete understanding of what is Django admin interface. How can you enable Django admin interface
in your project? How can you access it? And we also going to
understand what is the role of Django admin interface
in our project. Let's get started. So as of now we have
our model created. We have the model also
mapped onto the database, but its attributes
converted into columns. Now, the next step would
be to populate data into this particular tables in the database. How do we do that? There are two ways
of populating data into the table that
we have just created. One way that you can run
SQL queries to enter data. So this is a slightly
trickier approach, but this is doable. You can do. You can run SQL queries. You can run SQL queries
from the BG admin. You can click on the SQL
tab and you can do that. However, there is
a better approach when you are ready Django. Django provides an
admin interface which you can use
to manage data. How do you use an excess
the admin interface? So let's explore that. So you have to make sure first that your server
is up and running. So I have my server
up and running. And we'll go to the browser. Now in order to access
the admin interface, I have to type in the
local host, IP 12700. So this is the local
host and this is where my Django is running
on a thousand port. And I need to put
in slash admin. If you want to check the
URL on your machine, usually this is the URL, but when you start the
development server, you will have this URL being
printed on the console. So you can just copy this, paste it, and append
this with admin. The moment you do
that and hit Enter, you will see this
page loading up. This page is nothing but
the Django admin page. And you have a formula which asks for
username and password. Now, what is the username and password that we're supposed
to enter over here. In order to enter the
username and password audio, we need to create a
superuser for us. How do we create
a superuser now? We need to head over
to our terminal. So I have a second instance
abdominal running over here. And this instance has already been logged in
into virtual environment. Alright? And now I'm going
to create a superuser. In order to create a superuser, I'll type in the
command python three, manage BY create, super useful. And I'll press enter. We got an error because we're not in the
project directory. So if I type in the directory, we are not in the
project directory. I have to go to the
project directory, which is nothing but
the Django course. So I have to first
navigate that. And then I have to run
this particular command, python three managed
BY create superuser. I run this command. And now it's asking me, what's the username that I
want to create the user with? Leave blank to use vessel. So this is my system username. So it's just picking
that if you want to use the same user
as that of system, you can leave this blank. I'll just type in admin here. It's asking for email address. I'll just press Enter. And it's asking for passwords. So Atlanta some password. I'll enter the password
again and press Enter. The password I have Antonio is very simple and easy to hack, so the password is too short. It's 1234. It does not contain at
least eight characters. The password is too common and the password is
entirely numeric. So Django has a speech or venues prompts you like if
your password is weak. But this is just a sample
project that I'm creating. This is not a
production ready app. There is an option here. It is asking me, Do you want to bypass the validation and create
the user interface? So I'll say Yes, I
want to do that. You can see the message will you superuser has been
created successfully. Okay, so I see this
message being printed WO, which means that my
super user is created. Now as a next step, I will head over to
the Django admin tool. And I'll say facile
with you and as a 1234. And I'll hit login. Sorry. So we didn't use vessel, we use admin actually, and we use 1234 login. The moment do login, you will see this homepage, which is nothing
but the homepage of Django administration. And you can see OVO, you have authentication
and authorization. So you have two fields, groups. And uses, if you click on users, you can create user 0. So we have one user already, which we just created
from the command line. If you click on this, this is a superuser. You have the password encrypted. You you can't see the password. You can modify the profile ear. You're going to add a FirstName,
lastname, email address. You can scroll down
and you can see which groups is
to use a part of. Or if you wanted to add
this user to a group, you can do that from you. But right now we don't
have any groups added, so we're not seeing
that information you, but if you have any groups
information available, this is where you can manage it. Then you scroll down, you have different permissions that
you can assign to the user. All right, So you can manage
all the permissions here. In order to assign
permission you need to select and just
click on this app. You will see that flowing
over you like this. If you want to
remove a permission, you need to just click here. You have this last
login information you and D joined
inflammation as well. This is nothing but
about the user. How can you manage users? Or you can go ahead and
create multiple users. You can add users from you. More users will be created. You will be presented
with this form, OK, and you can keep
on adding uses. This you have to do if you have multiple users using a system. Then we have the
concept of groups. When you can create
groups for your users. As you can see, this
is pretty helpful. It helps you do all the admin related tasks
corresponding to your app. Alright? But one thing you
will say, Ask me that he, in the beginning you
mentioned that you can use admin panel to add data into tables that
you have created. So ideally, I don't see any information around
employee, Are you? Alright? I can see users or these users are being
saved in the database. If you wanted to see where
this uses are being saved. You again go to multi-user. Select this and you
can see all rows. You can see one administrator, we're essentially
whatever you create from command line is being
created in the database. We don't see employee you. So how do we bring
employee you and start adding all the employees. In order to do that, you will have to do some
configuration changes in your application and
in the code for that. And we are going to
head over to item. We're going to open second app and we're going to open models, sorry, not models, admin. We have this file at main.py. This file contains
all the information of the logistic models. So whenever you want to add a model onto the
admin interface, you have to register
it over you. Whichever models you
are registering, you are reflected on
the Django admin tool. In order to register with you, we need to type in admin
dot site register. You need to pass in
the model name also, this model we haven't
imported yet, so we will have to import it. Say from DOT models, import Of see employee. Let's save. I'll just switch to another
terminal and you can see is still up and running
the no issue whatsoever. Alright, now I'll head over to the Django admin tool and
I'll just refresh this. The moment due to
fresh, you will see a new entry appearing over
you called second app. So this is our app
name, second app. You can see below
the second app we have employs model
being distributed. You can click on this employees. And if you go to the database, if you see the employee
table, you are right. So there is no data
literally as of now. But we can start adding
data by clicking on Add W. I'll add, I'll see employee one. Sorry, firstName. First one. I'll save the last one. I'll say 28. And I'll save the. When we do Save, you can see this employ your
object is saved. You can click and you can see the information on
what you have saved. And you also have the ability to edit and update and delete. We have saved this now, head over to the
database and we will do a refresh, refreshed. Then we click on you can see this record
is being in total. You, wherever you
are adding from the admin panel is being
added into the database. And entering data is
so easy in Django. So if you didn't have this tool, you would have to write
manually scale queries. So you are getting the significance of
this particular tool. The importance of the stool. It makes the developer's
life very, very easy. We literally didn't do
much of coding you. For this particular tool. To get enabled, it
will just in-built. We did some
configuration changes, urine dip of a couple
of lines of code, and we have it up and running. Now if you want to edit, you have to just
click on employees. You have to select
the employee object. And you can edit 11. I'll save. And then I'll just refresh. Refresh. You'll see first 11. So that is how you again
a bit and you can even delete this by clicking over you and hitting
the Delete button. So this is how you can work with the Django
admin panel to add multiple records into the models that you have
mapped onto the tables. So that's about this class
guys, in this lecture, we understood what is Django admin interface and what is the importance of
Django admin interface? We configured Django
admin interface in our project and we saw
running up in life. We also entered the data from the Django admin
panel and we saw it being entered and reflected
into our database. So I hope you guys enjoyed this class and found
this class valuable. I shall see you guys
soon. Thank you.
24. Fetching data from database and showing to: Hello guys, welcome back. In this lecture we
are going to start fetching the data that we've
saved from the database. And we will be displaying this onto our
application interface. In short, we are going
to start fetching the data from the database and
use it in our application. By the end of this lecture, you are going to have
a complete clarity on this entire process. And this lecture is
going to be fun. We are going to learn a lot. Let's get started. What
do we are going to do essentially is we are going
to create a URL endpoint. And we're going to access that you wanted
from the browser. And that particular
URL is going to list all the employees
from the database, but all the information it
is just going to show us. This will help us
understand how you can interact with
the database and how you can fetch the
data that is already stored in the database and
use it in your application. So let's get started. So what we're going
to do is we are going to create a URL. So let me head over
to the browser first. We are going to create
a URL called employees. I have already this. So we're going to create
this particular URL. And when you hit this
URL in the browser, you should be able
to see the list of all the employees that have
been saved in the database. And you can see we
are getting four, not four as often now because we haven't done anything yet,
we haven't configured. So let's start the
configuration step-by-step. The first step is to define this particular URL
into our project. What we're going to
do is we're going to head over to our app. All right, heel, we will have
to create or URLs dot p-y, which will have the list of
all the URLs for our app. What I'm going to do is I'm
going to open the first step. You want to start BY. I'm just going to
copy this code. Close. It doesn't just to
save some typing your foot and I can
click on new file. I'll say you want a dot, sorry, u dot v y. I'll hit Enter. I'll paste this code. Remove this last URL or you. Now I'll define the URL or you're going to
create is employees. Alright? This
particular, you want to map two views dot employees. And this particular you want
to list called employees. We are just keeping employees, employees everywhere,
keeping it simple. And I hit Save. The moment I hit Save, nothing happens
because I don't see any ping on the console. That's because this
particular URL, it is not added to the main app. And in order to add
to the main app, we need to click over u. We need to include
the second app, your as well, like we have
done for the first time. This is how the application
will recognize the URLs of your application also which are defined
within the application. Just replicate this, I'm sorry, I will just copy this.
Replicated over u. I'll say second app. Let's see if the moment I hit Save, you will
see some error. You're on console if
you're always running, I'll just expand this a bit. This is known. It says second app.vue has
no attribute employees. The reason we are getting
this error is because we have written views
dot employees OU. And that is no view
defined as such here in this particular
view sort Dui, I'll say def, define
the employees function. Okay? You're sued by default, accept requests and hit Save. And now we're going to
start writing code, which we get all the
information from the database. So what do we need to do
is when the user hits this particular you
audit employees, we are calling this
particular view. This particular view would be
responsibility for fetching all the employee details from the database and pass
it on to D template. Alright, so let's first fetch the employee information
from the database. So what I'm going to
do is I'm going to say employees is equal to, I'm going to see
employee objects. That's it. So this is just the one line that you need to
mention in order to tell Django to fetch all the employees from the
database that have been saved. But I wanted to use this. If you save the file, you will not get an error. So we haven't imported, but that's fine since we're
not getting an error, we are not importing it. And I'll be opening this
views.py well before step. Here, you can see we have done a rendering of the
template and we have imported HTTP response. I'm just going to go to the views.py of the second appeal. And I'm going to render and pass this information
to the template. I'm going to see a random
sorry, you're done. Randall. I'm going to see a request is default
object here. Then I'm going to see
Employees dot HTML. And I'm going to pass
this pedometer TO YOU. Employees, Colin, employees. And let's see if we have
successfully passed the employee information
that will be fetched from the database onto
this particular template. The problem is this
particular template does not exist yet. So we haven't defined
as blood yet. If you try to access
this, let me refresh. Okay, so first strategy
we are getting is employees nor defined. Okay, so like I said, we
need to import employer. We'll we were not getting
any error over here, but when we tried accessing that you wanted to
regarding data, I'll say from DOT models
import employee alerts, save, refresh does not exist. So we need to create this
particular template here. I will handover to
the templates folder. I'll right-click and
say new file dot HTML. We have this template now. Now this particular template
has this particular object. We're passing this
particular object here. This particular template has access to that
particular object. I did a mistake. I love to
rename this particular file. Extinction is not write HTML. This particular template has access to the employees object. What I'm going to
do is I'm going to write in some ginger
Kotler William. I'm going to create
a for loop here. Now in ginger code, you can write a for-loop, you can write an if statement. So I'll just give you a demo for loop on how you can write, like I'll say for employee. Employees. So this is the
code that I'm writing. I'll see paragraph
here also be deck. I'll just close this. I need to say employee
dot first name. This is a property that
we are trying to access. I'll just duplicate this three times because there are three properties for every employee. So I'll say firstName, lastname, and then each. Then I'll have to
use t for loop. I see. Four. We need to close the loop
manually you I'll hit Save. All right, so what we
have done is ve got this employee object
from the view and V, it reading through this
employee object and printing all the information onto BY UI. And we have done this using the for-loop,
a simple for loop. Alright, head over to our browser and I'll
just hit refresh. You can see we have the
employee information coming onto D interface and this is the employee that is being
fetched from the database. This is very realtime, like if you do any changes
into the employee table, those changes are
reflected a wiggle. Let me give you an example. So if I go to this
Django admin panel, if I add one more employee, so I'll say first Two, Last two each, I'll say 22. I'll save. We have to employ your objects now and
I'll just hit refresh here. You can see this new
employees also added. If I make any changes to
the existing employee. So I might change this
name to do to alert save. And I'll hit refresh. You can see photos to do. What do we have done is
we have almost created a dynamic webpage which does not have a lot of
HTML right now. All right, you can write
a lot of HTML or CSS. You can style it,
but it's dynamic. So all the information is, whatever it's displaying is
coming on from the database. And we have done this with
the help of triangle. This is how you cannot fetch and save and retrieve the
information from the database. And this is completely
real-time like we saw. It's reflecting
all the obliques. It will reflect all
the deletes as well. That's about this class guys. In this lecture,
we learned a lot. We learned on how we can make of beach dynamic with
the help of Django. I hope you guys
enjoyed this class and found this class valuable. I shall see you guys
soon. Thank you.
25. Django Model forms: Hello guys, welcome back. In this lecture we
are going to talk about Django model forms. By the end of this lecture, you are going to have a complete understanding
of this concept. And we will also be understanding
how can you configure your own model forms in your Django application?
Let's get started. What are Django model forms? Django model is a special
class that allows developers to convert
them models into a phone. This saves developers
from writing code to create their own forms and reduce the application
development time. So right now what we
have been doing is we have been entering the data from the Django admin interface
and we have been doing this via a form, let's say. Alright, so this is the
Django admin interface and we have been doing
it via this form. Now, what you might want to do, like you might want
to allow users to create or add
their own employees. You might want to
give users access to this form without giving them access to the
Django admin interface, you want to have this form
into your application. How do you do that? So
in order to do that, you have for Django model
class which you can use and you can
create amazing forms. So let's see this in action. So what we are going to do
is we are going to create a form forward or entering
the employee information. And we are going to allow the employee add that
particular information. We are going to have
a new URL nucleated. And this URL will be
create an employee. We're going to go to this
particular URL create employee. And as of now we are
getting full North Pole, but went to your inter
period employee, you will see a formal you. All right. We will be first starting
the configuration part. And for the configuration
part we will be starting with the file
called forms dot p-y. We don't have formed
at BYU idiot. Okay, so we'll create
a new file form dot PY and C form dot v by address. And we have this form created. Now, we will start defining our form and which fields do we want to use from the model? And we want to convert
them into the form. So we'll start with, we're going to define a class. We are going to
see employee form. And we'll see forms
dot model form. Palms is nothing but a glass
that is available in Django. So I'm going to say from
Django import forms, we have this form glass
imported into our application. Now what I'm going to do, I'm going to write some code. I'm going to say glass, metal. So this is another glass
that I'm creating and I'll see Model is equal to employee. Since I'm using employee, I'll also have to
import employee. So I love to see from DOT
models import employee. Let's save and heel are
also specify a parameter. So I'll say Fields is
equal to, say all. This means that I
want all my fields that are defined in
the model employee. Do we convert it into a form? Alright, and I'm
taking the help of this particular class
called modal form. Within Forms. Forms is nothing but a package. I'm sorry, I said this
is a class earlier. Forms is a package under which we have modeled
form as the glass. This is about D forms dot p-y. Now, what do we
are going to do is we are going to head over to our view and the
view we would be. So here we have a BYU. Alright, whereas w dot p-y, this is W dot p-y. We will be defining the view
called create employee. And I'm going to pass in
the request object here. I also need to map
the water use. I'll go to you wanted to start BY I'll just
duplicate this line. I'll add a coma you first. I'll paste, I'll see
create employee. I'll say views dot
create employee. And I'll name the view
as create employed self. This is done. Now heal and abuse dot p-y. This view is being mapped to that particular you
want to know where you're going to
see employee form. Is equal to employee form. I will just create the instance of this particular glass
that we have created. After I've done
this, I also need to add the import statements. I'll see from dot forms
in both employee form. This is done. We are getting an
error no module named second app dot forms. So we have created,
formed or BY. So I'll just remove
this and Alex, if the error goes up, it will give you a good thing. And error invalid syntax
informed stored BY. So I'll just go to Formulas and we don't have a
colon define them. So I'll just hit Save. The old errors GloVe. Does no. Okay, now what I need
to do is I've created an instance of this
particular formula. You now I need to pass this
instance onto my HTML. So I'll just copy this line
over here, that underline. And it will save a bit
on the typing effort. And I'll create, sorry, create employees
employed or the HTML. Employ form. And you, I'll say employee form. All right, so we're
passing this. Now we need to create this particular HTML
file. The new file. We have created this HTML. Now, we are getting that though, employ form object that is
being passed from the view. Now we need to get
that object and we need to use
that formal wheel. How are we going to do that? We're going to first create
the form object of the HTML. I don't need glass
and action, are you? So I'll just remove this
methodology to post. Now. Here, I'm going to use that
particular form and I'll just specify that form
like this in ginger code. And I'll add a button. Modern type submit. In the back. I'll have the copy as seeth. Now whenever you are
using a post requests, you need to use the CSRF token. Percentage. I need to use CSRF token. Oh sorry. It is an autocomplete.
I keep forgetting. I said CSRF. Alright, this is done. We have our form ready. Now let's see this in action. I'll just hit Refresh over here. The moment you hit refresh, you're getting an error. Employee. Let's see
what data are done. Let me refresh. Got the issue. The issue
was I did not save. You wanted to start BY so when I hit save and
then refresh, it will. So you can see the form. This is a form that is
created like we didn't do any like much of coding
to create this form, we just converted a model. And that model is automatically converted into this
particular form. Like, I know, like it's not
looking that great because we haven't added CSS and
editing as of now. Like barely any HTML
be overwritten. But you get the idea if you write CSS and
if you beautify it, like you can make
world-class applications. We have created the form. But if you try to enter any
information, Are you okay? If I tried to enter in information
and if I died with it, save, it won't save the
employee in the database yet. So if I try to refresh this, you can see that
employee information is not coming in the database. And we have just configured
the form to display the UI. We haven't configured it
to save the information. I'll just pause the
lecture here right now because this will be becoming
fairly long lecture. In this lecture, we
understood how can you use Django model
forms in your project. We understood this concept of
Django model poems, how it, why it exists, and how it makes the life of developers
very, very easy. I hope you guys
enjoyed this class and found this last valuable. I shall see you guys soon. Thank you.
26. Saving data from ModelForm: Hello guys, welcome back. In this lecture we are going
to start saving the data that we have entered in our model form that
we have created. By the end of this lecture, you will have a complete
understanding of this entire process
and you will be able to implement
this in your project. So let's get started. So we have our Django
model formed ready, you're up and running
and on the browser. So right now, we are not able to save any
information from you. To save the information we
need to make certain changes. So here, the forms dot method, we need to map this
form onto view. I'm going to say action, and we need to add
the action tag. The view we are going to map
it to is create employees. Create hyphen, create employee. This is the view we
are mapping it to. This view is the same view that we have used for
showing the form. All right, now what? We're going to
make some changes, like we're going to
add an if condition. So we are going to
see if request dot method equal to host. This is post, then then
we need the entire phone. What we're doing
is we're checking what is the request type. The request type is not post, then this form is being
called to get rendered. But if the request type is post, so for example, if we are entering the
information and saving, then the request type is post, which means that we need to
now see if the information, in that case VIA checking. And we'll write
some code or where you will get the formal way you form is equal
to employ form. And I'll say request dot boost. And then I'll check
if the form is valid. I'll say form dot is valid. This is nothing but to
check for validation error. So all the validation errors
are also managed by Django. If we have a valid form entries, what we're going to
do is we are going to hit form dot safe. All right, so after
we have saved, we need to redirect. Okay, So I'm going to
redirect the user. This is the function that
we are going to use it. So redirect function,
using which we can redirect the user after a
particular action is done. I'm going to use
this function and I'll be redirecting this to, let's say after we have
saved the employee, we want to redirect the user to the list page listing all the employees so that you
can see the updated list. We are predicting there. And then I'll add
the else condition. Like this here. If the request method is post, then we're saving
the information. If it's not, then we're just
rendering the form. Alright. I'll hit Save. Hopefully
I won't get any errors. I don't let me refresh
and see check for errors. I got an error where you this method is written in caps
probably that's the issue. Change this to short form. I'll save, refresh. You get another error saying
redirect is not defined, so I need to import redirect
from Django shortcuts. Just start the input statement. I'll refresh again. You a urinal. I need to go to Create employee. So we add on Create employee. We are going to create the
employee using Django form. We're going to see first
meme 11111. All right. I'll say last name 11111
and I'm going to say 33. And I'll hit Save. It's throwing an error. It's saying create
employee not found. I got the issue. Basically the issue was we're not supposed to mention
the name of the view you. We did a mistake.
Instead we need to specify the name of the URL. So the URL is create employee,
correct? No problem. I'll just refresh this. Refresh I'll say first
name, last name 111. And I'll say Grady do.
And I'll hit Save. And you can see this particular information
is being reflected, NVivo also being redirected
to the list page. What exactly happened is when we first tried
accessing the beat, it checked whether the
request type is post. It was not. It went to the else part
and it rendered deform. This is a code which was
already working earlier. Then, once we hit save, it again called this
particular URL. And it again went to this
particular same view. But this time the request
method most post. Since the request method was supposed to regard
the form object, we checked if the form is
valid and we hit form sieve. And then after saving, we redirected the user
to employ speech. We are seeing the uploaded
list of employees. This is how you can save
data onto the model form. You can also see
that the saved data is being reflected in
the database as well. So you can see over you seen this information in
the database as well. So that's about this class guys. So in this lecture we
understood how can you save data from the model
form onto the database. I hope you guys enjoyed this class and found
this class valuable. I shall see you guys
soon. Thank you.
27. Form validation: Hello guys, welcome back. In this lecture
I'm going to talk about the form validation
part in Django. So by the end of this lecture, you are going to have
a complete clarity on what is form validation and how can we use
it in our project. So let's get started. We have already done form
validation in our project. And if you observe
our code over u, so I'll just tell it to our IDE. And you will notice
that video in views.py, we have used these
two lines of code. We're checking if form is valid and then we
are saving the form. So what does this mean? Django has some inbuilt
default validation, which is picked up from
the models you define. When we created our models, were you in models.py we have defined some
restrictions over you, like the maximum
length can be a 100. And we need to have
all the fears as well. Let you cannot store
empty values of these restrictions
are by default added onto more than form. Let me show this to you. I have my elbow up and
running or were you and I have also loaded this particular
page, create employee. So if I enter a
random string of you, you'll see that I can't
go, alright, current type. Beyond this. Now I'll
copy the string. I'll paste it over you. You will see the string
has a 100 characters. This is the tool that I'm using, word counter dotnet to count the characters and words
in a given string. You can see the string
has a 100 characters. If you try to type in
beyond 100 characters, you won't be able to. Which means that this
particular field has a restriction of a 100
characters as a limit, which is nothing but
the restriction that we have specified in our model. Now, one important
thing also to note is the HTML part has no
restrictions defined. We have just used
the form as it is. So this is something
that you should know. Now if I try to
save the employee, I'll get an error that this
field is not yet failed. So we need to enter
the value euros will. And if I tried to save, it will tell me
This is not fair. That isn't in milk validation that is already
presented to you. It does check whether the user is entering the
valid values are not. We are verifying this
with the help of this particular methods
over u is valid and save. That's about the form
validation in Django. I hope you guys enjoyed this class and found
this last valuable. I shall see you guys soon. Thank you.
28. Templates and variables: Hello guys, welcome back. In this lecture we
are going to talk about Django template language. And within that we
are going to talk about templates and variables. So by the end of this lecture, you are going to have
a complete clarity on these two concepts of bleeds and variables in
Django template language. Let us get started. We will first start by talking
about what our templates. To know more about them. We will head over
to the template FOR loop and we will open this file. False dot HTML. Template is nothing but an HTML file which can
render dynamic information. So this find that we
have is an HTML file. You can see HTML
code written here, and the extension is
also HTML inside HTML5. But this particular file can render dynamic
information like name. And hence, this is nothing
but a template as well. So a template is nothing but an HTML5 which can render
dynamic information. This dynamic information can
come from various sources, like database or different
forms in the same app as well. You can see this name variable is displaying a
dynamic information. So this is about
templates, right? And templates, it's
something that we have created quite a few
times in this course. Now, what are variables? So our template can
render variable values. We can pause these variables from our view to the templates. And these values can be
rendered by the variables. So let me explain this
to you so you can see this name is available and we're getting this
name from our view. If I open the view
under full step, so let me open the file. You, you can see
two false dot HTML. We're passing this name
variable with the value by ten. And this value is being printed. Name is nothing but a variable or a
placeholder which gets replaced during runtime with the actual value of that
particular variable. Now, variables are always written between
double curly braces. So you can see we didn't name
between WHO Liberty says, this is how you write
and use variables. So that's what a template
and variables are. I hope you guys now have a fair clarity on
these two concepts. That's about this class guys. In this lecture, we learned what our templates
and variables. So I hope you guys enjoyed this class and
found it valuable. I shall see you guys soon. Thank you.
29. Working with Tags: Hello guys, welcome back. In this lecture we are
going to talk about how can you work with bags in Django and know
how tags are apart of Django template language
help you do a lot of things. By the end of this lecture, you are going to have a
complete clarity on or tags and how can you use
them? Let's get started. What are tags in DDL? A tag is nothing but be soft code which is
written something like this. So you have a curly brace, percentage, the name of the tag percentage
and ago eukaryotes. So you would have a tag name, you're in the same dorm. In bleeds, there are
a number of tags that are used and give you
an example of tags. We have if-else statements, we have tanks for, for loops. We have tags for include
and block content. You can write the if is
to validate a condition. You can write for
loops to run loops, and you can have
tags for inheritance to tax for inheritance and nothing but including
block-oriented. If I take you to our
Django editor atom, if I open the first
dot HTML view, you will notice that
you have used this tag, which is nothing but CSRF token. So this is nothing but note
bag that is available. Now, one thing I would
like to highlight for you is there is a difference
between a tag and vw. You can write dynamic variable
using two curly braces. Tags are surrounded
by these percentage and going places and tanks are used to define
the logic in the templates. So that's about tanks guys. So I hope you guys enjoyed this class and found
this class valuable. I shall see you guys
soon. Thank you.
30. If else statements: Hello guys, welcome back. In this lecture we are
going to talk about if statement in Django
template language. By the end of this lecture, you are going to have
a complete clarity on what our if-else statement
and how can you use if else statement in
your Django and leaves? So let's get started. If else statements are
nothing but statements that are used to evaluate
a particular condition. So there might be some
tasks which you want to do, or they might be something
which you want to show to the user if a particular
condition is met, that is red, if it's
conditioned, come into picture. Is nothing but the
syntax of how if it's conditioned on written in
Django template language, you have if condition, which is nothing but it's a tag. So you can see it's surrounded by the curly brace and
percentage symbol. Then you have the body over you. You can say if a
particular condition, and then if that
condition is true, then this body is rendered. You can have else
condition which will get evaluated if
the condition is false. So if this condition is
true, you'll notice body. If the condition is false, you didn't know this 40. So that is how it works. If you're still
confused and if you don't have clarity yet, you would have shortly once
we do our demo example, we are going to drive the demo. And let's say you want to
print a message on the screen. If a user is above
18 years old each. We're going to drive this
example in our Django code. Let's say we have this 50k
or full starter HTML which we have already written
in. Bleeds for loop. Now, let's say for example, I wanted to print a message that you are above beauty
news of each. This message wouldn't
be putting their only if the age is above 18, use an EEG is obedience
that we want to evaluate. So in order to
evaluate and right, if conditional you, we will need access to each
variable we are. We can pass age variable
from the views. So I'll go to the views.py of Falstaff full-stack FOR loop, I have this particular
file called views.py. And here is where we are
calling false dot HTML. I'll just pass one mole
panopto will you see each? And I'll pass the
age as credit do. Alright, so I've passed
the age is 20 to do. Now we have masking this
age as a phenome DO, similar to like we
have passed name. Now while HelloWorld to
default dot HTML and overview, I'll write the if
condition I type in. If you can see I'm getting an autocomplete
OU, I'll press Enter. I got if an end if you
automatically printed card this statement and
I'll put this within if I wanted to print this
particular statement. If the age is above AD, see if each is greater than using this age is
nothing but the age 3D, but we're getting access
to from views.py. So it is getting passed from you all and we are accessing it. Or you that said we
have written all simple if condition which gets
printed if the age is above. I'd save this and I'll make sure that my development
was running. I had a whoop to a browser
and I'll hit refresh. We had on the wrong URL we
add on Create employee. And this particular phi is
called from HelloWorld. If you go, do you ought to be,
you're calling HelloWorld. On helloworld, you want to just copy the cell
where you want it, and I'll paste it over you. So localhost slash hello-world. I know you-all seeing this, you ought to both eating, use. Now if I change age or you. So let's say if I go to views, if BY and if I make hs, then if I hit Save, if I had to finish this, this message goes away, which means that the condition
that we have pleased in Django template is
working perfectly fine. And it's indeed working
with the real 3D out there, which is changing its value. Now as of now, we
have hard-coded the value of age in views.py. But you can fetch each
from anywhere like you can fetch from another form using
a GET or post requests. Or you can fetch from
the database as well. So it's completely
dynamic information, which is right now in volts. So this is how you can walk
with the if condition. Now let us try or
the else condition. Let's say you're bringing
you that if the ages of 18, you're saying you're
giving a message, you want to avoid
waiting years of age. But I also want
to give a message if the user is not about
reading Utah Beach. For example, in this
case, we have hs, then there is no message
that is being funded. We go there don't have is
conditioned mentioned you, you will have to specify. So this is the S stack over you. And you will have to
mention what do you need to bring if this condition fees
if age is greater than 18, if this is true, you print this. If this is not true, then you are not above 80 news. And I'll save this and I'll
run this, I'll refresh. And you can see, you'll seeing you on not above
80 news of each. We have seen an example of
if else condition in works. Now, there might be
scenarios reading. You might want to evaluate multiple conditions at one goal. For example, if
you are printing, you are above 18 years. If the user is above 18 years, you'll printing, you are not above 80 news if the user
is not above a genius. But let's say I wanted to add one more condition that
you are off 80 news. So if the age is equal to 80
news you wanted to print, you are eating needs of each. Well, how would you do that? I love now we are evaluating
true-false condition only. You can add one more
condition or you, I can see hold on. I'll add a tag or you autocomplete
is not picking it up. So I'll see elif is equal to AD. This is one more condition
that we are adding. And lateral you do. Bad news. Is now I'll hit refresh. Nothing changes. We
need to make each as a dean in order to see
this getting changed. I'll just refresh. You can see you already ages 18. Now, along with true
and false condition, we've already evaluating
to true in if statement. Else most evaluating if
the if statement is false. So it was executing
the block of code. If the if statement is false, what do we have one motor
condition checker will you help of L If tag? And we are checking if the
ij is equal to eating. How the logic works is false. This is evaluated to
see if age is above AD. This is printer. If age is, then this is evaluated. If this particular thing fields, if this pretty good,
I think pulses, this is printed and
this is exerted. If statement is exhibit. But if this is not true, then this is evaluated. This is printed. And then in the end, you see this as the output. If none of the conditions that this is how if
else statement works. And this is an example
of ladder effects. So this is also called a ladder. Ladder because there are multiple condition checks,
one after the adult. So you can have as many
checks as you want. You can offend checks,
elif, elif else. If you can add a leaf, you can keep on adding
a left over you. You can keep on
evaluating the condition. So I can say elif
again over you. You can do that. Where do we don't have that
requirement right now, so I'll just remove this. But if you have that
Guatemala in your projects, you can definitely do that. This is how if else
condition works. And if this condition
is very modern DAG, and it helps you
evaluate conditions and do certain actions when a particular
condition is met. That's about this class guys, in this lecture, we understood
what is if else statement. How can you use lateral
if-else statement? And we saw all of
this would be headed bulk or demo in our project. I hope you guys
enjoyed this class and found this last valuable. I shall see you guys
soon. Thank you.
31. For loops: Hello guys, welcome back. So in this lecture we
are going to talk about for-loops in Django
template language. And by the end of this lecture, you will have a
clear understanding of how can you use for loops to do repeated stuff
in your Django templates? So let's get started. Django provides for
loops which you can use in the Django
template language. You can use it in
Django templates. So let me show you
how can you use them. So you can say for you, and we'll get to auto
suggestion for you. You can press Enter. You can see this is the
syntax of for loop. You can say for a
in the variable u. So I can say really
believe can be the names. So if you have a list of names, you can read through that list using this
particular for-loop. It is nothing but the
counter which goes to each and every name in
this particular list. You can have a p
tag, paragraph tag. And you can see, I love. And you can put in the names
like this, sorry, not names. You can print a yo-yo because
a is what We're using. It read through this
particular list. But we need to define this particular list
somewhere, right? So as often all we
haven't defined names. Anyway. What do we are going
to do is we're going to go to views.py. We're going to have
names over you. And sorry, I'm going to posit doesn't list
and I can say Java. I'll put the names of
programming languages, Lighten. I'm going to see Android list. I'll hit Save. And let's run this and
see this in action. You can see VSA, I love Java, I love Python, I love
Android being printed. Wo, this for-loop is similar to the for loops
that we use in Python, except the fact that we are
using this in the HTML code. We add accessing
this dynamic lists which is coming from views.py. Now we can get this list
or this information or this day dot from any
metric can come from any form. It can come from database. And Amanda's completely
dynamic and view is responsible for providing
this to the template. Template will then access this and it will use it
in the for loop. And we have a counter,
you're a witch, Brings each and every
element in names. Or will you. We have just added a statement. You are, I love and we're bringing that
dynamic information you how you can use for loops in Django
template language. I hope this was pretty clear. And I hope you guys enjoyed this class and
found his last valuable. I shall see you guys soon. Thank you.
32. Using inheritance to organize templates: Hello guys, welcome back. In this lecture we are going
to talk about how can you use inheritance to
organize templates. And by the end of this lecture, you are going to have
a complete clarity on the concept of
inheritance here. We're also going to learn
about two new topics, like include and block content. That's what we are
going to learn. Let's get started.
There might be scenarios wherein you
might want to have a base template and use a
base template to define some base configurations
like the base color, etc. If you are a user of web, if you visit Amazon.com, you will see most of the websites have a
standard structure. Your Amazon has a
structure of header. This header is constant
across all the beaches. This is the homepage. And if I search for yoga mats, you see this header
is still the same. This part below changes. This is depending on what you search and
more direction to do. But this header and these minimum options are
seeing across the website. You have a footer
also at the bottom. Scroll a bit soluble to the
homepage. Throw a little. You're just food and
also remains constant. So many websites or all the
websites that you visit, like most of the websites have the standard structure
but in the half of Edo, which is constant
across the website. And then you have a food hub
which is also constant like header and footer motor
constant is what I mean to say. How would you achieve
this thing in Django? One way is you have ten pages, you create ten HTML templates. You have o Header and Footer Code defined
in all ten of them. That is one way
to do about this. But the problem is
if you have too, make a simple color change, you will have to do it across
all the ten templates. There is a possibility that you might make errors, mistakes. You might miss some templates. These are all the
possibilities and it might also repetitive tasks
for the developer. How do you solve this problem? This is where the concept of inheritance comes into picture. So you can create
a base template in Django and you can
inherit that template. Other templates. Let me
give you an example. I hop onto our ITU and I create a template,
be stored HTML. This is our base template, which we'll define all
the B's configurations of AHRQ website. I'm going to be some go to you. I'll base this. It'll have slash body. I'll have slash HTML. This is the base
template which defines the HTML and the body tags. I haven't opened the
border died yet. So what I'll do is I'll
open the body tag. Sorry, I shouldn't have
closed the border. Died without opening it. Just opened the motor deck. I'll mention you
background color. So let's say I want to have a constant background color
across my whole website. I wanted to have the
Gallo as I save this. Now, what I can do is
this is a base template. I can use this template and inherited all the
other templates so that this base
configuration of color, background color is
equal to grid is applied across all my templates. And how would you do that? You need to specify a tag
called block content block, and then block, and
I'll specify content w. This is block bag that we
have which we are defining. We are done with this HTML. Now let's move on to
folders dot HTML. Now we have created
this based on HTML, and we need to inherit this particular HTML file onto the first
started streaming. So what I'm going to do is
I'm going to remove this, all this information
you the more redex move this as well. I'm not removing form because
that is something we need. Just move this form dy over you. Then I'm going to specify
a tag called extends. We have an extent tag. We will specify
be starting HTML. So we are saying that we
want to extend the HTML. And I'll hit refresh. We aren't seeing anything yet. Now, we need to also specify and mentioned the block content. So I'll say block content. I'll take this n block and
I'll put it to the end. Let's save and I hit Refresh. So on doing the refresh also, we are not getting
the gray color you. So let's see what the issue is. That's specified extends a
specified block content. We did a mistake. We have specified Biggio you. So BG is not attack. We need to specify BG color. And that hurts safe. And let me refresh. And you can see the
background color of this particular page
is changed to gray. Let's talk a little bit
about how this code works. We first defined base dot HTML, which is nothing but
the base file which you can use across your application. And this HTML has defined
the background color. It has stalled, or
Django that this is where the block will come in
whenever you are inheriting, that will be replaced
or you heal. What you've done is you've
extended be start HTML. You have specified that this
particular code that is written between the block tags is nothing but the
block content. What happens is this
particular code of this particular entire block
goes and sits over here. Doesn't how well we can use an organized templates with
the help of inheritance. Very important feature
is because you can have of file called footer.html and you've been
cleared the photo. And you can use that
particular file. You can inherit that
in all your templates. So the food WE consistent
across the whole website. If you want to make
any small change, you have to just make that
change in that single five and it will be reflected
across the entire application. Imagine without this feature, you would have to create footer.html every value
of two copy-pasted code. Then if you have to
make any changes, you have to remember where
all you have be stirred that that's not the right
approach to go about it. This is a made-up route
wherein you modularizing your code and you are inheriting them if you
are creating components. So FUTA is a component, handout is a component. The color scheme that you're using as a
component in all of that. This is pretty helpful. Let's summarize this lecture. In this lecture, we
understood how can you use inheritance to
organize employees. I hope you guys
enjoyed this class and found this class valuable. I shall see you soon. Thank you.
33. Real world project : What are we going to build: Hello guys, welcome back. In this lecture we are
going to talk about a project that we are going
to build from scratch. And the project that
we are going to discuss is our
to-do application. You can see the project
is loaded in my browser. And this is what
we're going to build. What I'm going to
do in this lecture. I'm going to give you
a complete overview of what we're going to build. And I'm going to give you
a overview of each and every functionality that
this particular project of us will have. So let's get started. I have this application
loaded in my browser. This is nothing
but our to-do app. You can see there
are some Toulouse already loaded into this
particular application. These are already added. Every two Lou has a button
or they have two buttons, Update and Delete button. Using the update button, you can update this particular
two-loop. Using delete. You can delete this
particular tool. You have a text box along
with the submit button. You can add our
two Lu from here. Let's say if I want to either
do LU, bring medicines. Again, right, the to-do
name and I can hit Submit. You can see the blue
being added over you without the page
getting refreshed. So this is how the add
functionality works. Then you have a BW. You can click on a bit
and you'll be taken to this page and you can
upload, bring milk. Today. I can see submit. The moment you say Submit, you will see this
particular todo is updated to bring make great. I can also mark the
Hulu as complete. So you have this complete
checkbox over you. You can see complete
and you can hit submit. The moment you do that, you will see the to-do is
striped off from your list, your list, and the two-loop
is striped off. Right now. I also have the ability to
believe D2 so I can delete, bring medicines which
had just started. I'll be taken to this
confirmation page. And if I hit submit, that particular todo will
be deleted from my list. This is that invoking or
for this particular app. And you can see we have some
basic styling done in place. We have discard
structure along with some shadows and a
background color. Background color, we have set
to white mark in the end. And after building this app, you can decide and style it
depending on your needs. This is the application
that we are going to build. An also a couple of things
I would like to mention. We are using a
combination of databases, Django framework, and we are using the
template language as well. And we will be also
writing some HTML CSS or you get or to beautify
this particular page. Also, we have done little
beautification, not much, but we will have to write
some CSS for the same. This, the other day you are
seeing on your screen in the application is coming
dynamically to the database. So we are using Postgres SQL. We'll be using the
combination of postgres SQL and the BG Admin. And you will see this information coming
from the database, which means that this information
is completely dynamic. And even if you
shut the Silver of your application and if
you restart the server, you will see this
information being displayed. Again. It's being stored in database. And it's not independent audits and posting in the app only it's being
stored in database. So this is an overview of
what we're going to build and we will be learning
a lot by building this. But I hope you guys had excited. I'm excited for this. So let's get started. I'll see you guys in the
next lectures. Thank you.
34. Creating our app and setting up the database: Hello guys, welcome back. In this lecture we are going
to start walking towards blinked Hulu app B. I'm
going to create an app. In this particular lecture, we are going to do
the project setup. And we are going to also set up the database to
work with our app. That's what we're going to do. And let's get started. So by the end of this lecture, you will have this project
setup on your machine. You will also have configured the database for
this particular app. Let's get started. First. Or what I'm going to do
is I'm going to collapse this particular project which is already open you in Adam. And I am right now in the root directory of
this particular project. I'm going to shift, I'm going to come out
of this directory and I am in this
particular folder, you, this is my pot grad. I am right now. And under
the spot I have two folders. One is the virtual environment and one is the project folder. Now we need to create a project. And this project will be
our two-loop project. So I'll say Django
admin, Start Project. And I'll call the
project to project. And I'll hit Enter. Press ls. Ls will list all the files that exist in this
particular for-loop. And you can see we have Hulu
project created over you. So one thing to
always remember is if you want another
project root directory, you need to come out of
that root directory using this particular command
and independent directory, you need to create this
particular project. The project is created now, and I need to make sure that
I see the project here. For that, we need to add this particular
project into atom. And to do that,
we'll go to file. We'll say Add project FOR loop. And we'll navigate
to our course files. And we will select the
two-loop project overview. And I'll hit Open. You can see we have this particular project
added in odd atom. Now the next step is to
start an app, or were you? I need to navigate to
the project first. I'll say cd, blue project. I'll say to you,
I'm just increasing the foreign sites so that
you can clearly see here, I need to type in Python three. Manage dot p-y. I need to say start app. I'll call it the app. As to the moment I wrote that, you can see two LW is being
added to my project folder. This is how you can create the app and
set up the project. Now we can run dy, so I'll run the server by running the
command python three, manage, don't be shy. Run, so I'll press Enter. And the project is
running now on this URL, I'll just copy this URL. Go to the browser and
base two you audit. You can see the
project setup is done. Now after the project setup, we need to configure
the database. What I will do is I'll
hide award to settings.py, Hilton settings or PY, I need to start
configuring the database. I'll navigate to
the database stack. And I'll add some information. So we need to add
the name over u. So we need to add
the engine first. So I'll just add the
engine tag here. As of now, the engine that is available default
is SQLite three. I changed this to
full-screen as good. Then I'll specify the name
of the database here. So the name of the
database can be, I'll see the name of the
database is todo app. I can say two-loop project. Okay, so let's keep
it to do project. And I have the user information, password, and host and port, which are the other tax
that we need to mention. I just add in this video, we have user as Postgres
forward as 1234. Host is our local host
because give you the basis available and running
on our local machine. And then we have to report
information as well. Now, we have done the
database setting. And you will see that once you see if this particular
file settings or PVA get an error on the console saying to do project
database does not exist. And this is true. We haven't created the database. In order to create
a new database. We will go to PG Admin and we
click on database and will. Right-click and
we'll see database, and we'll call it to loop
project. We'll hit Save. The database is now created. You can see the database. I'll just collapse this
particular second app database. And you can see blue
project is created you, if you hit Save now or if
you restart the server, you will see the error is gone and database
is being picked up. My jangle. We are done by
creating the project, setting up the app, and
connecting to the database. And we had also done
with the database setup. Now the next step is to
create the models and get those models or the
database tables created. So first we'll start by creating the model
here in our project. So I go to the blue app
and I'll open models.py. Not all, we need to start
creating the model. What model are we going
to create in our app, sample app we saw
here you could see we have to store every
to-do information. So we have to do LU
name and some Deleuze, not some like all Toulouse
can be marked as complete. You need to also keep
the track of that, like whether to Louis
complete or not. So you need to
store balloon name, whether the do loop
is completed or not. And we will also be scoring
vendor to loop was created. Let's head over to this
particular file OU, and we'll see glass task. This is a class
that will define, we'll import models from
the mortals package. And the first field
library or cure is task, which is nothing but the Garfield and the maxlength of this particular
field is a 100. I copy this and I'll
paste this over you. And the next field
that is, is complete. Now is complete is
nothing but of view, which will help us keep
a track of whether a particular todo is
marked as complete or not. We will not be keeping this particular
field as character, will be keeping this
as Boolean field. Because we believe
extruding through volts. So it's completely true, means the blue is
marked as complete. Complete false means that
blue is not yet complete. And default value will be. So we have an ability to
define the default value you. And I'll say false. You can read more about a boolean fields where
you're at Django. Form fields. If you move this,
if you go with you. This is the link to the
official documentation. We can see form fields
Django project. If you click on Boolean field, you can see this is the
field that we're using and you have an option to
specify default as well. We'll be using this
field and we are done. I'm adding it and
login copy this, and I'll paste this here. Now the next field that we
need to add is created. This is nothing but
the date nine feet. And I add o phenomena you now at adding this
particular parameter or add now is equal to two. What this parameter is going
to do is it is going to make sure that we don't have the ability to edit
this particular fee, but this particular field
is added automatically. So we don't want
users who add task while adding does to select unlike what is the time
when they're writing. Because this can be able to
write it if you didn't want the users to select
the date and time. So we have configured a
parameter called worldwide now, which will make sure that
this particular field is auto populated and auto set and use it as not asked anything
about this particular field. This is something
there'll be at writing. I'll hit Save what were you? All right. The model is created now and
what do we need to do is we need to migrate this particular model
into our database. And we need to see
if we are able to convert this particular model
into our database people. What are you going to
do is the next step. We're going to go
to settings or PY, and we have to add the app. So we will have
our tag for apps. You have the app tag
called install apps and you need to
add the blue app. I'll hit Save. So todo app is now added. The installed apps
and install apps is in the settings are
within the project folder. Okay, so we're done with this, and now it's time
to do a migration. We have to now make sure
that all the moderns, not all, we have only created
one more than we have to make sure this model is
reflected as a DWG able. To do that, we will have another instance,
optic dominant open. Switch over to the
project directory, starts running the
commands that are needed to migrate the model
to the database. So I'll say biotin three, manage PUI, say mic migrations. Best end up. Another moment I do this. I'll see the migration is
being created over you. If I click on this,
you can see fields id, dusk is complete and created. Id is nothing but
meat or to edit ID. I'll just close this. So everything seems fine. I can even check my migration. So I will run this
command by pin three, manage BY as good and migrate. I'll see Hulu and I'll
see one placenta. And you will see
this SQL that will be executed and
everything looks fine. This is optional
step to CVS, good. But if you wish to see,
you can see it this way. By reflecting my
model into database. Run this command python3, managed dot p-y migrate. And I'll press Enter. The moment I do this, you will see everything being OK. And now I'll go to pg admin. Go to schemas. Under tables, I should be able to see all the tables along
with To-Do Tasks table. You can view the reduct. Table will be MDS off now, okay, but you can
see you have ID, you have task with
the limit of a 100 is complete set to
Boolean and created, which is nothing but for date and time on when
the two Lewis added, we had done with the table
setup, database setup. And we are also done with creating the project
app and the models. In this lecture, we setup our project app and the new
two BCE for R2 application. And I hope you have been able to do the same
on your system. Do I hope you guys enjoyed this class and found
this class valuable? I shall see you guys soon. Thank you.
35. Setting up models in admin: Hello guys, welcome back. So in this lecture
we are going to set up the models
in the admin panel. By the end of this lecture, you will have your models
visible in your admin panel. So let's get started. Here I am on the item and
in order to do the setup, I'll just minimize
this domino of mine. I'll switch to the
other dominant. But in I can see my
project running. And I'll switch a wall to
this admin dot p-y fight. What do we need to do is we
need to register our model 0 so that they are reflected
in the admin panel. What I'm going to do
is I'm going to see admin dot site, DOT register. And I'm going to mentioned
the model class, and I'll say Save. Now the moment I hit Save, you'll get an error. You're on the console saying the name task is not defined. And that's correct. This file won't
know what task is unless and until you
import task over you, you need to import tasks. So you will say from DOT models import
task, I'll hit Save. The moment you do that, you will see the error go away. Now, we need to go to a browser and I'll try
accessing the admin panel. So I'll see 127800 slash admin. Now, we need a
username and password. In order to get this
username and password, we need to create a
superuser. For that. I'm going to head
over to our console. You, I'm going to switch the on and I'm going
to create a superuser. Alright, I'll see biotin
three, manage dot p-y. Goodyear, super-useful. I'll press Enter. And it's saying leap blank to use facet, I'll say email address. I don't want to enter
password is 12341234. Again, it will remind me that my path forward
is very simple. Do you want to bypass
the password validation? I'll say yes. Doesn't not recommended for building production ready
apps in production, ready apps, you need to
have a strong password. This is not a production
ready app or I'm not going to deploy this anywhere and
use it commercially. This is just for learning
and educating bubbles, so I'm fine with
using this password. Now, I will switch over to
the Django administration, which is nothing but
the admin panel. And I'll enter the credentials of the user that I
have just created. I'll see vessel 1234
and then say login. The moment I log in, I'll see all the models
that I've registered you. So we have registered
this one model you tasks. And we also have this default groups and
uses available you. If you click on task, you'll see that you have
the ability to add tasks. Are you going to add task? I can say bring chocolate so you can see
some of those suggestions. And I'll say safe. This particular
task is added you, you can use this
admin tool to manage, I had believed tasks. So that's about
this lecture, guys. So in this lecture, did a setup of models, ambulance disturb those models to our admin panel so that we can add manage lead our models on the goal
from the admin County. And we should also
be able to see this change being
reflected in our database. If you refresh the database, you can see this field is being added in the
database with all the values. So that's about
this class, guys. I hope you guys enjoyed this class and found
this class valuable. I shall see you guys
soon. Thank you.
36. Displaying tasks in a template: Hello guys, welcome back. In this lecture, we
are going to start displaying the tasks
in our template. By the end of this lecture, you will have a complete gravity
on how could you display all the tasks and you can display it by fetching
it from the database. So how can you do that? You will have a complete
clarity on each anybody steps. And we're going to
simulate each and every steps here so that you could replicate
those steps on your machine in your
project as well. So let's get started. So objective today is to display the list of tasks
that are added in the database on in
the home you want it. If I try to access
the app, will you? For right now we are seeing
this default page over u, which is nothing but the default page that
Django provides. Instead of this page, we
have to see the list of all the tasks that we have
added in the database. In order to do that, I'll switch over to atom. And I'm going to first start
by configuring the URLs. I'm going to go to
URLs dot p-y. Here. I'm going to add Bot, and I'm going to
Django to include all the URLs that
we have in odd app. So I'll say blue
dot you audience. I'll hit Save. The woman. To hit Save, you
will get an error that include is not defined. So you need to import include
from Django dot URLs. I'll see coma in-group. And I'll hit Save. The
moment you do this, the included or goes away, but you see another error. The error is no more dirname
to do, lord, you orders. So it means that
in our to-do app, we don't have any module
called URL, which is correct. We need to create this module. We go to the app and we'll
see you want us dot PY. And I'll pay some color wheel, so I need to be
scored from pattern. Do you want to start
BY? And I'll be suitable you move this. We need to start defining
the box for the homepage. The homepage will
be represented by the MD inverted commas, and we need to specify
the views of you. I'll just remove this. Here. I'm going to
see views dot index. This is the view name
that we have to define. And I'm going to mean the
view as meme is equal to, I'm going to call it
list and I'll hit Save. Now, we have saved this. And if you'd try
to refresh this, something happened in no
module named Blue Dot URLs, but we have already added this. I don't know why they
said it is still coming. Let me stop this over and
let me start it again. I'll start this over. Okay, So now they are
changed and that we are getting now is
muses not defined. So within views we are trying to access index and
that is not defined, which is perfectly fine. So we need to import
views over u. So I'll see from dot
views and I'll hit Save. You can see now the
address changed again. So from todo dot views, todo dot views has no attribute
index, which is correct. Like within views we haven't
defined the index yet, so we need to define
an index here. So we'll say def index. We have requests as the
parameter and heal. We will start defining
the logic to fetch the tasks from the database and pass it on to the HTML template, which will render this
information in the but also, let's start by fetching. Task is equal to how
do we fetch will see the mortal name dot objects, dot fetch all the Deleuze
from the database. And I have to now return. And I have to render Albert
rendering of a beach. And I'll say index.html. This index.html does not. Instead, we need to create it, but for now I'm specifying the HTML template name and I
need to pass basket object. To see task you. You can see this always up and running the moment
that saved this, the order it over into way. But it was not able to
find the index in views. Go to the browser and
I'll hit refresh. And you can see now we're getting the name
task is not defined. You are trying to access the
model from the views are BY, but you haven't imported it. So we need to import that. So I'll say from dark
model's input mask, I'll hit Save, hit Refresh. This editor was expected. We haven't yet created
the template yet. So we need to start
creating the templates. And for that, I created
templates for the first TO YOU. This folder, templates. This is where all our
templates will reside. I agree the new file, I'll
call it index dot HTML. So what we now need to do is be on now passing
the task parameter. And this task is
nothing but a list of all the objects that we're
getting from the database. But the help of this model, we need to start
printing the blues. So the Toulouse we are assuming
is in the form of list. So I need to go to index.html and I need to
start writing the for loop. And I need to see for tasks. In task, task is the variable
that we are getting. Our task is the list that
we're getting from views.py. And here I need to
see bad enough task. And I need to, you mentioned
tasks and I'll hit Save. And now we still need
to do one more step. So we have computed
the templates, but we haven't told
Django project on the location of where
our complete fives decided, we need to do that
configuration as well. To do that, we handle
those settings are p. And here we have the
stag and bleeds. And here we need to configure
the directory of employees. So we need to see OS
dot, dot, dot join. Okay? I needed to see BCE DIR. Goma emulates. I need to hit Save. The moment I hit Save,
it says not defined. So you've got this editor
and the cell will stop. You need to import OS. So I will go to the
top and I'll add an import statement
in both voice. I'll hit Save and I'll
start the soul again. You can see it was now up
and running but no issues. You have your
templates configured. Now let us see if you can access all your Toulouse
in the browser. I'll hit refresh and
you can see you're seeing a task object
being put into view. Now the reason for this is, let's head over
to our HTML file. Now. You are getting the list of objects and not
the list of tasks. So our task is nothing
but a glass with a model. And this particular patch is done from the
database in the form of objects in order to exist
the name of the nostrils. So if you take a look
at model sort BY the task class has a field
on an attribute called task. Since we are getting tasks
in the form of objects, if you need to specify
tasks, dot basketball you. If you do this, it'll
start printing the name of the task because
the name is getting saved in this task failure. If you don't do this, you will see the objects being printed like we are seeing now. Since we have made the change, I'll hit Save and I'll
refresh the browser. And you can see putting chocolate is being
fetched over you. And if you go to the database, you will see we
are fetching this from the database itself. Now, in order to test this, we can also start
creating more tasks. From the admin panel. I can see bring milk. I'm going to save. Again fish the page. You can see bring milk
is coming over you. And it's also being
added to the database. You can see putting
the ink coming over u. So this is how you
can essentially fetch the list of all
the tasks that are being added in the database
onto your browser. I hope you guys have
aphasic letter D on how you can do this. And I hope you are also according with me and
doing this along with me. In this lecture, we understood
how can you DO and fetch the list of all the tasks
that you are saving in your database with the
head bulk Django admin panel. I hope you guys
enjoyed this class and found this last valuable. I shall see you guys soon. Thank you.
37. Creating form to add tasks: Hello guys, welcome back. In this lecture, we are
going to start creating a form to add tasks
within our application. By the end of this lecture, you will have a
complete clarity on the step-by-step
configuration that you need to do in your project. So let's get started. So now we have been able to create tasks from the
Django admin panel. But doing this from the Django admin panel
is not intuitive. And if you see the demo
app that we have over u, we should be able
to create tasks right from the
application itself. Like it won't be logging in into Django administration and
uses wouldn't be doing that. You need to have the ability
to add to lose Yoda itself. In order to do that, we
will be creating a form and we'll be taking help
of Django model form, which is nothing but a
special class that allows developers to convert
them mortals into forms. This saves developers from
writing code to create forms and reduce the
application development time. We have already created
the model with you. So we have this model setup. Now, we will be converting
this model into a form. How do we do that? So we
need to go to forms dot p-y. Forms dot p-y does not exist. So we need to create this particular file
under the app for loop. I create forms dot BY. Here. I need to start
creating of glass. So I'll see glass task form. And I'll say forms
dot model form. So I'm using this class model
form from forms package. And I need to import this
particular package you, I'll see from Django
board, it forms. I'll hit Save and
I define a class. I'll say model is equal to task. This task is nothing but our
model that we have created. And I'll press Enter
and I'll also see fields is equal to all. We need to add all the
fields into our model form. Now, this done, now
what I'm going to do is I need to head
over to our views.py. So you wouldn't views.py. I'm going to create an object of task form glass
that we just created. I'm going to see form
is equal to ask form. And I get an error if I save this because I haven't
imported this, I need to import this. I'll say from forms. Import basketball. I'll hit to see if the
moment you do this, you will get an error
saying task is not defined in forms dot p-y. So I'll go with you. Yes, we haven't imported task with you. I'll see phloem dot
model import star. I'll import all the models. Let us save this always open and running and all
the others are gone. Now we have got an instance
of form in views.py. Now we need to pass
this object into our views so that we can use this particular form
in HTML template. I'll say formal. Were you the name of
the variable is form. I'll hit Save. All right. Now, what I need to do is I am passing this
particular form object as a parameter to the template. Now in the template, I need
to display and add this form. To add this, I'll
be adding this at the top and I'll see form. All right, so this is
all of you out a form and not also add input button. And I'd say input type is submit and I want to call
it create task. So the name is create tasks. And I'll remove the value
bottom. I'll let save. Now let's head over to the browser and
let's do a refresh. We are getting another
form is not defined and we're getting this
in views.py belief. Not be asked form. Let's head over.
You. You start BY, I believe we have
imported task form. F is capital U. This is the error we made. F. Capital F is small. Modal class name has capital F. So we need to go to views.py and change CS2 capital
F and hit save. Refresh. The moment you do this, you will see this DOS
form coming over you. And you're going to
add tasks from you. So I can say bring
groceries and submit. It's not submitting
it because we need to write the code to
submit the Blues. Often all we're just
displaying this form onto our user interface. All right, so in this lecture, we understood how can you add form onto your user interface. And we used Django
model class for this, which converted our
model into a phone. I hope you guys
enjoyed this class and found this class valuable. I shall see you guys
soon. Thank you.
38. Saving todo’s in database: Hello guys, welcome back. In this lecture we are going to talk about how you
can save your to-dos from the form that we have created on our browser
into the database. By the end of this lecture, you will have a complete
clarity on the steps that are needed to achieve
this functionality. So let's get started. We have already displayed
a form, alright, but we are not able to
save any information yet. In order to save
the information, we need to add some functionality or we need to tweet this
form a little bit. Let's head over to Atom. And he'll, I'm going to
navigate to the template. And here we have added
this particular formula, or this form has an input type. So what I'm going to do is
I'm going to add a form tag. You put this code like the form and
the input button into this form tag like this. And I'm going to
remove glass over you. The action is, where do we
want to redirect on Submit? We want this request to
go to the row divided. The method is post. Alright, I'll hit Save. The moment you hit
Save now, Menu Submit. If I refresh this, and if I add bring chocolate, and if I submit, right, we're seeing this editor
CSRF magnification field. Like always, if you're
using a post requests, you need to add CSRF token. Alright. I'll hit Refresh. Cancel. I'll go back. Now
I'll hit Submit. So let us see whether we are
getting this error again. I'll hit Refresh, refresh. I'll say bring milk, putting medicines,
and I'll hit Submit. So we are being taken, do the rudy water, alright, but nothing
is happening. This is not getting
saved because we are yet to intercept this
request and we are yet to save this to the database by mentioning the slash you're
going to start BY. But do you added sodium nor
this you ought to start BY, but this one, you're
going to index views. All right, so in views
you have this index. Now. You need to get this form and see the
form into the database. How would you do
that? You will see if request dot method is
equal to if it's post. Then what are we going to do is we're going
to get the form. So we're going to see
Task Form and we're getting this DOS form
from the request. So I'm going to
say request post. And then we're going to
check if the form is valid. So if form is valid, then we'll see form got save. And after the saving is done, you will see the return redirect and you'd be redirecting
them to be seawater. But what we are doing
is we are checking if the method request is post. Request method is post, then we're getting
this request from the HTML page from the form. But if the method is not host, then somebody's just loading this page and hence does
information will be loaded. But if the request
method is post, then we're getting the form. We are checking if the form is valid and we are hitting save. This save function
will make sure that the data that is entered onto the form is saved
in the database. Now after saving, we
are refreshing and redirecting the user
to the homepage. And this will ensure
that the web page is reloaded and the newly added to Lou is also reflected
on the webpage. What I'll do with you is we need to go and
we needed to hit, Refresh, see, fresh, see, bring, submit, not seeing the
desired result yet. So let me check
what the issue is. Once we have added
this onto views.py, we're going to navigate
to the web browser. We are going to refresh
the page and I'm going to add it to
bring milk too. I'll hit submit. The
moment I hit Submit, I get an error that
redirect is not defined. So it's because we
are using redirect, what we haven't imported it. I'll say redirect.
I'll hit Save. But we got this
error after saving. So basically first we are saving and then we
are redirecting. So the to-do must
have been saved. So let me refresh this. You can see the
Buddha was saved. Now let me type in again. Bring chocolate to the
stain and Alex submit. And you can see we have
seen this particular todo being reflected
here in our list. So I hope you guys have a fair clarity now
on how you can save your Toulouse and start
adding to lose right from the front-end or
right from the browser. Django admin panel also you
are reading from the browser, but this is essentially you
are doing from the app. I hope you guys have
a favorite clarity on the step-by-step
configuration part over you. And what do you need
to do to achieve this? I hope you guys enjoyed this class and found
this class valuable. I shall see you guys soon. Thank you.
39. Updating todo’s: Hello guys, welcome back. In this lecture we
are going to add the functionality of
update to our interface. So we have our app
running and we are able to add the Toulouse
right from our app itself. So now we need an
update functionality. So once you have added a To Do, you need a button or were you using which you can
update a particular tube? So if you check
out our demo app, you have an upload
button and you click on Update button to update
that particular tool. We need to add a
similar functionality into our app. How do we do that? Let's get started with step-by-step on how
we can achieve this. Start this, I will first
headword to distort BY. Alright, and we need to define. You ought to hold on Before
you want us to talk BY. I will head on to index.html
and healed in index.html, I'm going to add
the update button. So let's say I wanted to
add an update button here, let's say within the loop. So I want every task that we are displaying on the interface to have an
update button beside it, I'll be using the
ETag of the HTML. And in place of this HRTF, I'm going to add
some ginger code. I'm going to say, I'm going to add
something like this. And I had some CO2 video. So I'll say if a
user clicks here, this is the updated link. So if the user clicks here, I want the user to
be redirected to update underscore
task. You wanted. I want to pass the task dot ID as the pedometer.
And I'll hit Save. Let me just show this to you in the browser so I'll
just refresh this. We haven't registered this tag. That is what a spelling. So we're specifying this URL name along with the parameter, but you want to do is
not yet registered. So let's head on to the you
ought to distort BY heal. What I will do is I'll
plot function you. I'll just say will you update,
update, underscore tasks? And I'm accepting the
task id as the parameter. You, if you see I'm
passing the task ID. So I need to accept
that task idea. We're going to see
STR, colon key. This is how you are
accepting the pedometer. So you are saying string
and the parameter is key. So this part of the
URL is dynamic. And you want to
redirect the user to update task in views.py. And I call this URL
as update task. We are using this name of you that we have registered
the URL with. This is the name that
we're using here. We're specifying just a name. So this is the benefit
of defining means. You have defined this with
the name update task. Anymore you want to
use this, you want to, or whenever you wanted to
specify this you audit, you need to just mention
the name of the US. And I'm specifying the
parameter also that this URL will accept. Now in views.py, what
I need to do is I need to add the update
tasks method or you, because we have Gordon
error that there is no update task in views. I'll say def update task. And it will accept the
request has the parameter and also the parameter
that we're passing key. There will be two parameters. I'll just add this and now you, we need to fetch
it a task first. What will be the update process? We need to get the
task with D key. This key is nothing but a unique task ID that we
have in the database. We need to fetch the
corresponding task. Let me explain this
to you bedrock. So I will do this
example project. Now when you click on Update, clicking the update button, the side bring groceries. When you hit Update, you'll
see the URL update task slash 1414 is nothing but
the ID of this task. Bring groceries. And when you click on
this form is loaded with deep pre-filled information of this particular two-loop. You know, what this
to-do is all about. Now similarly, if you
click here to update, you will see bring milk today
and also complete a stick, which means that this task
is marked as complete. So we need to create
a similar form when we see this information of the corresponding task that is being clicked
on, pre-filled. Alright, How do we do that? We need to fetch the task force will
be fetching the task. Task is equal to
ask dark objects. Dot get an ID is equal to C0. Instead of getting all the
objects we have just seen get and we're getting
the task would design. Now, what I'm going to do is I'm going to also get
the form object. So I'm going to save form
is equal to task form. All right, and I'm gonna say
Instance is equal to task. This should make sure
that we initialize the form with D task object
that we have retrieved. And then I'll press Enter
and I'll say it or don't. See you request first, then the next pedometer
is update task HTML, the HTML that we
are yet to define. And then the dose
I'll pass in form. Say form, Gordon, form. I'll hit Save. What we're doing is we're getting the task. So whenever you click on
the Update button here, so let's say you are
loading all the tasks. So let's say you click on a bleed burden on
the third task. Three will be passed
as the task ID. Ok. And you'll go to
this particular phi u and views.py task
is being called. Now you'll get as the
pedometer in the key field. And you'll get the
corresponding task of having the key to the
corresponding dots, which has two, will be
fetched from the database. And then we're creating a formal object with this
task being initialized. So this particular form will be prefilled with this
particular task. And then you'll passing this form onto the
update test.html. Now we haven't
created a test.html, so we need to do that. So we'll see new fight Update. Now we will be
writing some code. So you will say h3 and I'll add update task
as the heading. And then we'll create a formula. So I'll say form glass so we don't need gloss
over you action. We don't want to
define any action yet. We'll define the method post. And I have CSRF token you because we're
doing post requests, you need to have CSRF token. Then I'll have formed deck. We're getting this form. You. Alright. I'll have input, type submit. And the name is a bit task. Hit Save. And let's see the updated
information on this, on this. To finish. And you will see an error, invalid blocks of the task, new register, or load this. All right, So we are
getting this information. The interviewer getting is
that this isn't registered. And I believe that's
because we have added this inverted comma will
you in the wrong place. So we need to add it over. You. Hit Save. And I'll just refresh. It's still not working. Okay, so I think we also need
to specify the URL or you. So I'll specify you
Waterloo you because this is something that we'll
be able to put in a URL. We will have to specify
just use water Diageo. I'll see if I'll hit refresh. The other changed. Okay,
So I got the shoe now. Saying task. So what do guessing
task for you? So you need to
change it to Tasks, then refresh so it
worked finally. Now you can see we have the update button with every
two-loop that we are seeing. Let me click on any
of the update button. So I click on this
putting chocolate. You can see without being
redirected to update tasks. And the idea of
this task is one. So if you check the due
to B's idea of putting chocolate is 11 is being lost. And you are seeing
this pretty full information in the field. Alright, so let me explain this once again on how this
and Dataflow works. Menu go to this HTML. Like the homepage. You are seeing, the update
button mean populated. Now this Update button is
being rendered with the URL. And the URL is oblique task and update dots gives you
wanted that we have defined u. So this is the
opportunity to ask you on it, Update Tasks slash, it accepts one parameter
which is dynamic, and it's the ID of the tasks. You're specifying the
idea of the task. And the view we have I just
Studio is update tasks. So when you call
this particular URL, the ID is being passed to
this particular view you, It's getting close
morning, dusk. And in Archie's, the 1-bit, the ID1, putting chocolate
is being fetched. And then last formal
object is created and it's initialized with
this particular tasks. Then this is being passed as a pedometer
to update test.html, which is an HTML file
which exempts to spit on my dump and
displays default. So if you click on
different Update button, you will see different
tasks being loaded. You will see the ID
will also change. So this is bringing
chocolate who has five SCID. You can see this is
an order to fresh. So let me refresh. So bring chocolate
to has five SDI. So that's how this glass guys. So in this lecture we
understood how can you start updating the Toulouse. We haven't yet
completed the process. Now we're just adding the
two-loop into the update form. And now, after
making the changes, you should be able to save this. Okay, which is not
happening right now. That was about in this class
guys, in this lecture, we understood how can you begin the process of uploading blues? And we have created
an update form and we have linked it
to our mean beach. I hope you guys
enjoyed this class and found this class valuable. I shall see you guys soon. Thank you.
40. Saving the updated todo’s: Hello guys, welcome back. In this lecture, we are going to start saving the updated tools. And by the end of this lecture, you will have a
complete understanding of all the steps
that you need to take in order to save the updated to lose
onto your database. Let's get started. I am on the speech and
this is the update page. You can see. On the update page, you can update the two-loop. I can say two to two. And I'm going to hit Submit, but nothing happens
if I hit submit. What do we need to do is
we are on Update task. We are redirecting
user to homepage over Bn artery directing user
actually to anywhere. The action is empty. What do we need to do
is we need to start updating the views.py.
So let's head on. Do we use dot PY?
And in views.py, we need to start adding some code for the
request type bolster. So after this line
of code over u, I'll say if request dot
method equal to post, then what do we need to
do is learn a co-linear, otherwise we will get an error. So we get the form first form
is equal to the task form. I need to get this task form from the post request
that we're getting. And I'll say Instance
is equal to task. And I'll say if form is valid, will see form dot safe. And if once they form is
saved out of redirect the user to the homepage, which is nothing
but the list page. Let me refresh this page and
let me see this in action. Let's go to the list page
and I'll hit Update, timesing, bring
milk 111 and I'll hit Submit. We are
getting an error. No attribute boost. I got the area. Also been gaps. I'll hit Save. And I'll go back, I'll refresh, look in a bit the milk, and
I'll hit Submit. We're getting form has
no attribute valid. We did another mistake. This is a function
and not an attribute. I just changed this to
function marketing this cool brackets and I'll hit
Save, I'll finish this. I'll say bring milk. 111, Submit. All right, so we've
got another error. It says it says there's
no function called valid. Hold on, so it's not
a valid, it is valid. We have saved this and
let's refresh this now. And let's see One,
One, One submit. You can see this has
been uploaded, alright, and you can update the
Deleuze from here, so you can see this is updated. This is also being
updated in the database. Alright, so let me refresh. You can see the 11111. We're getting there,
so we're building a dynamic app wedding. You have been able to fetch all the Toulouse
onto your browser. In the app. You can
add to lose from the form and you can update by clicking on
the update button. Submit it's being updated here. This is how you can
see the ability to lose onto your
Django application. I hope you guys
enjoyed this class and found this class valuable. I shall see you guys soon. Thank you.
41. Allowing users to delete todo’s: Hello guys, welcome back. This is Lecture b would be understanding on how you can add the functionality to delete, to lose from your application. By the end of this lecture, you will have a complete
understanding on how you can make this functionality
Voc for your app as well. So let's get started. Already have the
functionality to add, to lose, an update to lose. Now, we need to add the
delete functionality. So in order to do this, we need to first update and
add the URL to start BY. So we need to add
the delete URL. I'll just say, instead
of oblique tasks, I've just duplicated
the line and I'll see Delete Task will need
the same you wanted. If I go over you are demo app
and if I click on Delete, you can see it's the
similar you want to with variety is being passed. And if you hit submit, this to do with this
particular ID is deleted. So coming through our
app or that Louis, I have delete task. See glute task, you. And I will see Delete
Task here as well. If I have updated the water. Alright, now after
updating the URL, essentially I need to
update index.html. So I need to go to index.html. You and I need to copy this, and I need to be status and I need to
say Delete Task View. All right. I need to see delete the video. Hit Save. It's the
same structure we're calling the task
and passing the task ID. Now after we have
updated index.html, we need to go to views.py HTML. So sort of views.py, not HTML. And heal. I need to say delete tasks. I need to accept a
request coma key. We are getting this
request object and the key from the URL. I'm going to get this particular
task in a similar way. I got you. You got this task
with this particular key. I don't need to
create the formula. Instead, I'll just say if request dot method
is equal to host, you need to say task dot. And we will be redirecting
user to D homepage. So after we delete, we will be redirecting the user
to the homepage. Now, this chord when
we are deleting, going to be hitting
the delete button. But before delete button,
we also need to render, like we were entering you. So we needed to render. So I'll just copy paste this. And instead of this, I'll
say delete tasks dot HTML. We don't have a format video. I'll just remove. Alright, I'll see if you
can sort of form attribute. We need to add the
task attribute. Here like this. Let's see this in action. So let me refresh this page and let's see
if we get any error. We're getting an
editor or will you let me check what
the issue is, okay, so I've found the issue for why I was not able
to load the page, so I didn't see if
you wanted to start BY and there was no
coma you in the end. So yo you need to add a comma. At the end. I didn't die. And when I
hit Save to this fight, if I had a threshed, I could see the delete
button coming up over u. We have to delete button.
Let's click on Delete, so we get an area that
template does not exist. Just fine. Leave it redefining
the Delete Task and bleed. And blue that will be going
to the template directory, creating a new fight. Delete Task dot HTML. Alright. I'll be adding a message first, so I'll be seeing you sure. You want to delete you. I'm going to pass in the task name, passing the ETag. See percentage. Right here, I'll say you want
to type in the list name. Mistake. Yeah. I'm calling the URL list over
you and you want to list is nothing but our baseURL. We added this and this
button will be cancelled. So if the user says, I don't want to delete. We will just redirect
him to this base. You want it at the homepage. And if the user sees, delete this so we'll
add a formula, sorry. Instead of glass being
removed this class, he'll action we see nothing
and method is equal to host large CSRF because this is the post request
that we are sending. I'll have input, submit. This is done. What we are doing is we are redirecting user
to the task first. So when we go to views.py and once this function
is called Delete Task, so it's not a post request when it's called
for the first time. When you hit the button for you. It's not a post request, so this part is skipped. Basketball object is fetched
for the corresponding ID, but this part is skipped. And instead the scissor donors, so you already directed
to delete tasks dot HTML. So let me show you this. So you have to read elected you. And you'll be shown a
message like are you want to delete this
particular task? If you see, yes, if you submit, right now, submit does not have any value. So let me add some value. Say input lists
submitted, refresh. Some problem. Long you wait. All right, So it
worked perfectly. So there was an issue
with the value. So I just removed that and
had only the name attribute. Does is load it. Now, when you select delete, the host part is OEO in
the views.py is skipped. This part. And instead we are
loading the test.html. And it's asking me,
but that I wanted to delete this particular tool. It's not showing the blue name. What do we will be fixing this? And if you hit submit, it's deleting this particular tool. Let's delete this mic. But before that I'll
get that fixed. So instead of showing task, we need to show tasks
dot name, dot task. Because in models.py, we have
the activity name as task. Let me refresh alert, delete. Are you sure you
want to delete this? Submit? It will get deleted. Delete functionality is
working perfectly fine. Let me refresh the time. Let me show it to
you in the derbies. You can see only two blues now. The one with ID 13
have been deleted. This is how you can add delete functionality into
your django project. I hope you guys have affair
clarity on how you can make this work and how you can add a date functionality in
your Django project. I hope you guys enjoyed this
class and found it valuable. I shall see you guys soon. Thank you.
42. Marking tasks as complete: Hello guys, welcome back. In this lecture we are going
to understand how can you mock your Toulouse as complete? If you absorb you. Let me update this task, putting make that'd be marked as complete and
let me hit Submit. You can see we're not seeing
any change in the UI. We have mocking are
two Lu as complete. If you see this, it's
marked as complete. Alright, might be another reflecting that on
the user interface. So we need to do that
because you're in our API. We will striking off. So whichever to do is complete, we market striked off. Let's understand how are
we going to achieve this? So we're going to first headword to Atom editor and we're
going to load index.html. And we need to now check if
D2 is marked as complete. We have the task object OU. It would be to lose
marked as complete. We will be making
use of strike tag of HTML to mock or
to Lu as complete. And we will be making use of
the if statement as well. So let's see this in action. So let's start adding
the if statement. So what I'm going to do
is I'm going to see, if you'll see I get some
auto populated quarter. We're just going to
press Enter you. I'm going to check
if is complete. It's completed. The model
field that we have defined, it's a Boolean type. So I'll say if task is complete, then we need to do trike. We will be using
the strike back and we will be placing
the task within the stack and move
this to the end. And we will be
specifying the stack. That is it. Let's refresh our app and let's
see this in action. So you can see you have this particular
thing striped off. The problem is this is
going on a new line, and this is coming on the
same line as the buttons. I'm going to remove
the Beta view. And let's have this feedback. Let's save this,
and let's refresh. Okay? So in order to fix this, it all came in one line. So in order to fix this
allowed of p tag here, see if refresh, all
right, it's done. Instead of b. You can also add o, BR tag. Line break. Line break is
not leaving enough space. So I'll just see b and b. Let's save and I'll refresh. This is how you can market
to lose as complete. So if I hit Submit, you'll
see it's incomplete. This is complete. This is how you can add
the functionality of mapping task as complete
in your Django project. I hope you guys enjoyed this
class and found it valuable. I shall see you guys soon. Thank you.
43. Styling template: Hello guys, welcome back. In this lecture we are going to add a beautiful
user interface. We are going to beautify
interface that we have created for
our application. So as you know, like we have finished
functionality. Like we are able to
add tasks, update, delete, and multitask
as complete as well. But what our
obligation lakhs right now is beautiful user interface. So we are going to
beautify it a little bit so that it looks decent. So by the end of this lecture, you will have your
application as well. Look beautiful if you
follow along the lecture. So let's get started. So in order to start
writing some code, we are going to discuss
a couple of things. So we are going to add some
CSS onto our application. So CSS is in nothing
but scripting language which
beautifies the HTML if you are not aware of this. So I'm just giving
you the definition. And we'll be making use of something called
as Bootstrap CSS. So I'll be searching
for Bootstrap CSS. And you'll see the
first link here. Bootstrap is a project
which has standard CSS. This is nothing but a standard CSS standard that is defined. And you can use it
in your project. It's free to use. What I'll be doing is I'll be clicking on getting started you, and you can see over you
the link coping this link. I'll be adding a head tag. You're not a mixed
started streaming head. And I'll paste that over u. We have our CSS
added into our file. Now if I refresh, I might see a small change. A small change, which is okay. Now I need to start
adding some code. Alright, I'll add
a couple of views and I'll make sure this
form is center and all. So as of now, this form is on the top left, which is not good. I want it to be in the center, like we have for our demo here. What I will do is I'll start
adding a couple of deals. So I'll add this div
called Law Center column, you just ahead of the form. And as close to stiff. Let's see what changes we see. Once we add this node changes, then we'll be adding
one more div, which has few tags. Define if. I'll save, refresh. How Bootstrap works
is you have to, you can make use of classes. So Bootstrap CSS already has some classes predefined
in Bootstrap CSS. If you just started classes, those functionalities are
inherited in your project. That is how it works. So you'd see a lot more changes like as and when we
start adding some Codio. So let me add one more div, divs that I have added. Now what I'm going
to do is I'm going to add some CSS
data have written. I'm going to add the
CSS in head back. So let me add that in the
head tag allowed some CSS which I have written her to
save and I'll hit Refresh. So the moment I added the
CSS to center column here, you could see this particular form
coming in the same dome. And the center volume says, it adds border reduce mortality. This is nothing but like I
want some rounded edges here. I've defined more than reviews
box-shadow, box color. So this is the box background
color that we have defined, binding margins and the bid. Some CSS that we
have written here. And we saw some change
on our application. Now, let's see some
more change over you. It does button. We are going to make
it even better. What do we need to do is we
need to go to Bootstrap CSS, and we need to
search you buttons. You can see this CSS buttons. You need to click over you. And you'll be taken to
this particular page. And you can see these are in Milk Buttons, in Bootstrap CSS. And to add these buttons, do your project that
you just need to add these glass tags
in your buttons. What I'm going to do is I'm
going to use buttons success, which is nothing but
this green color button. I'll add this to our
Create Task button. So I'm just going to switch over you and I'm going to
add this glass here. I'll hit Save and we'll refresh. So you see this
burden is like this. Now, if I refresh, you see it turning to clean. All right, then I am going to add a
couple of more buttons, so I need a better button
for oblique and delete. What I'm going to do is I'm
going to have a bit marked as primary button and delete
marked as being geometry. All right, I'm going to copy
this primary tag from you. I'm going to go, we'll going to. Leads to the next one
is do being GO button. So I'm going to copy this. I'm going to paste it. You hit Save and
I'll hit refresh. You can see the buttons have
become much more better. Alright guys, so one more
thing I wanted to add, or you like, I just
realized that we were using the
login of Bootstrap. You accidentally, like
we came from Google, and we will switch to the
older version of Bootstrap. So we need to switch to the
latest version like this. So you have to click over here and switch to leaders version. Then you have to
click on Get started. So you will get this latest
version of Bootstrap here. So you need to copy this and you need to replace
the one that you added. But this one, and
you need to hit Save the moment you do that. Alert. And if you refresh, you will see this change. Like you will see this
form coming in the center. This is what we have done
and achieved with Bootstrap. Now, this is not an interface. If you see our interface, we have the task field OU, and we are asking
you just to mark the task as complete or incomplete while
writing the dusty. We don't want to do that. We just wanted to tell you
this too, and the dusk. And if they want to mark complete incomplete,
they can do it later on. In order to do that,
we will have to go to our index dot HTML. And we have added
this form over u. So here instead of
adding the entire form, we will have to
say form dot task. Task is nothing but the
field in the task model. We're just mentioning
that we want to display only task over u. I hit save and I refresh. You can see the updated
UI coming up over you. And I can click Update OU, I can see 123. I can hit Submit. I can add more tasks. So I can say bring groceries. Going to submit. You can see all the dots
being added over you. This UI looks a little
bit decent and by TO, as compared to having
nothing like we had in the beginning
of this lecture. Just to give you a, somebody of what we did in this lecture, we used Bootstrap CSS to
beautify our application. We also added some custom CSS that we wanted to
style our application. We added a few do tags with you, and we switched the entire form that we had to just
be task feeding. We also switched off buttons
to Bootstrap CSS buttons OU, you can refer to the
documentation of Bootstrap CSS. And you can also add all
of this into your project. So that's about this class guys. I hope you guys found this glass valuable
and interesting. I'll see you guys
soon. Thank you.