Python Backend Web Development Course (with Django)

**Creating a Token for a User in Django REST Framework**

In this tutorial, we will explore how to create a token for a user in Django REST framework. This is a crucial step in authenticating users in our API.

To start with, we need to create a new user in our database using the `admin` interface. We will use the default admin user credentials to test our authentication mechanism. First, we navigate to the `admin` interface and create a new user by clicking on the "Add User" button. We then fill in the required details such as username, email, and password.

Once we have created the user, we can log in to the admin interface using the default credentials. After logging in, we click on the "Add Token" button to generate a token for our new user.

Now that we have generated the token, let's learn how to use it in our API requests using Postman.

**Using the Token in Postman**

To use the token in our API requests, we need to go under the authorization section in Postman. We select "API Key" as the type and enter the token obtained from the admin interface. The value of the key is the token itself, followed by a colon, and then the user's username.

Next, we need to add this to the query parameters by clicking on the three dots at the end of the URL bar and selecting "Edit notes". We then add the token to the query parameters and send the request.

**Obtaining an Authentication Token for a User**

In order to authenticate our users without having to come to the admin interface, we can use the `obtain_auth_token` view from Django REST framework. This view allows us to send the user's credentials (username and password) to our API and obtain an authentication token in response.

To do this, we need to import the `obtain_auth_token` view and add a new path to our API. We then define a function that returns the `obtain_auth_token` view with the required arguments.

Here is an example of how we can implement this:

```

from rest_framework.authtoken.views import obtain_auth_token

urlpatterns = [

path('api/token/', obtain_auth_token, name='token'),

]

```

This will create a new path at `/api/token/` that returns an authentication token when called.

**Using the `obtain_auth_token` View**

To use this view, we need to send our user's credentials (username and password) to the `/api/token/` endpoint using Postman. We select "Post" as the request method and enter the username and password in the form data section.

Once we send the request, we should receive an authentication token in response.

**Benefits of Using the `obtain_auth_token` View**

Using the `obtain_auth_token` view provides several benefits, including:

* It allows us to automate the process of generating an authentication token for our users.

* It eliminates the need for manual logging in to the admin interface.

* It makes it easy to integrate with other systems and frameworks that use Django REST framework.

In conclusion, this tutorial has demonstrated how to create a token for a user in Django REST framework. We have also explored how to use the `obtain_auth_token` view to authenticate users without having to come to the admin interface.

"WEBVTTKind: captionsLanguage: enThis comprehensive course is for absolutebeginners, and will teach you back end webdevelopment with Python. You will learn thebasics of Python and Django and create a fewprojects along the way. Tommy has createdmany popular courses, both on his own channeland on the Free Code Camp channel. Hey guys,welcome to this back end web development coursewith Python. In this course, we're going tobe learning everything you need to know tostart your web development journey with Python.Let's take a quick look at the agenda of thisvideo. First, we will start from learningPython, which is a programming language we'regoing to use in this video. In the Pythontutorial, there'll be lots of exercises inwhich we're going to do together just to getcomfortable with the Python programming language.Once we are familiar with Python, we willmove straight into Django. Now Django is aPython framework, which is used for buildingserver side web applications. In the Djangotutorial, we will learn all the concepts youneed to know while getting started into January.After that, we're gonna build three differentprojects using Django. The project we're gonnado a blog application, a weather detectorprogram, and a real time chat applicationusing Django. We're gonna build out this projectso you get familiar with building your ownproject in jungle. After that, you are goingto get introduced into API's with Django,you will learn how you can view the rest API'sin Django using the Django rest framework.And I hope that after this video, you'll becomfortable with building your server sideweb applications using Django. Now, I havesome free resources like a Django roadmapPython data structure cheat sheet, a Djangocheat sheets are plenty more free resourcesin which are compiled into a PDF. And youcan download a PDF for free using the linkin the description below. And if you likemore tutorials like this, you can also checkout my own channel at COVID told me whereI teach more Python and web development ingeneral. Now have you noticed that let's divestraight into this video. This tutorial isa bite of food because we are going to belearning python programming from scratch.So this is a list of everything we're goingto be talking about in this video. So letme give a brief introduction to Python. SoPython is one of the fastest growing programminglanguages in the world. with Python, you cango into various fields like machine learningand AI, web development, and plenty others.So take into lambda scores and easy to learnPython with a very good decision for yourprogramming journey. So without wasting anytime, let's get straight into the tutorial.Right here, I'm just on my browser. So we'regonna download Python on our laptop. So todo this, I'm just gonna search for downloadPython for Windows since I'm on a Windows,and I'm going to click on the first link.And then right here, I see download Python3.9 point one, which is the latest version.So we're just going to click on it. And thenyou can see that it downloaded it automatically.So I already have Python downloaded. Now whatI just need to do is to install it, I'm justgonna come into where I saved it. And thenI'm going to run it. So make sure that whenyou're installing Python, you must stick thisout Python to path. If not, you're just goingto make it more complex. And it's supposedto be for you. So let's click install now.Yes. And so this is just going to installPython on our machine. It should take a fewminutes, a couple of minutes to install. AndI'm going to be back when it's installed finish.So right now the setup was successful. Soas you can see, the installation has beendone. So I can just click on Close. Now forme to confirm evolve Python installed, I'mgoing to open up my command prompt. So herein my command prompt, I'm just going to typePython. Once I type it, you should open upthis show. You might not understand what allthis is now. But this is just to verify ifPython was truly installed. So now that weknow we have Python installed, let's justgo ahead and install our code editor. So Pythonis the programming language. But we are goingto code we are going to program everythingor the Python we're going to do is going tobe in a code editor. And there are variouscode editors out there. We have Visual Studiocode, we have pi charm, we have Sublime Text,we have atom. There are counselors out there,but for this tutorial, we are going to beusing Visual Studio code. So let's go aheadand download it. So I can close up my commandprompt right now. So let me just say if youdon't know how to get your command promptYou can just search for it on your Windowssearch bar. So right here, we can just goback to Google. And then we can search for,let's say download Visual Studio code. AndI'll just click on the first one. So sinceI'm on a Windows, I'm going to download theone for Windows. If you're on Ubuntu or Linux,or Mac, download the one for your OS. So rightnow you can see that it is downloading. SoI already have it downloaded on my PC, I'mjust going to cancel that since I alreadyhave it downloaded. Let me just show you theinstallation process. So right here, I haveit downloaded already, we just click on Enterdoes to run it. So what it tells me here isthat setup has detected the Visual Studiocode is running. So this simply means thatI already have Visual Studio Code installedon my computer. So I'm just going to pressCancel. But for you, as a beginner, you wantto install this as a new software. So whenwe already have this installed, by just goingto open up our Visual Studio code, and thisis what it should look like once you firstopen it up. So now we have everything setup. We downloaded Python and installed it.And then we downloaded Visual Studio codeand installed it. Now we can go straight intocoding. So now that we have everything stored,what we just want to do is to create a newfile in this file is where we're going tocode all our Python. So in Visual Studio,good weather is going to come into the toolbar,and click on new file. So once we click onnew file, you can see it automatically asthis untitled name, but I want to save itby pressing Ctrl S. And I'm just going tosave it. First of all, let me say all filesare there now to save it as up dot p y. Sothe name of the file is up. But at the bottomof the file extension, I used dot p y. Soanytime we're working with Python, anytimemodule, create a new Python file, it mustalways have the extension dot p y does willmake whatever we are running on know thatwe are using a Python file. So now once Isave it is updated here. And as you can see,Visual Studio Code automatically detects thelogo of Python now does how to save gradesand save a new Python file. So this is basicallyhow everything looks like in Visual Studiocode. On the left hand bar, we have four bardoes we if we open in a folder, this is wherewe're gonna see all the files and foldersin there. We have this search this GitHub.We don't need to bother about that for now.But this is our Visual Studio code looks like.So since we have everything we know how tocreate a new file, what we want to talk aboutnow is the print function. So in Python, wehave some built in functions, that means somethings that already done automatically, whichwe don't need to write too much of code. Nowlet's say we just want to print us text tothe screen. Like we just want to show a userlike a Hello World or welcome, we're gonnause the print function, it is going to bringsome basic text to the screen. Now first,to do this, we're going to say print, andthen we're going to open parentheses. Andthen we can use single quotes. Or we can alsouse double quotes. There is no problem herein Python. But we can just go with singlequotes. So you can just pick one and go withthat. So in this codes, I'm going to writemy text like I say, Hello World. Now as youcan see, I have printed hello world. And Imust make sure I save this file. And thenfor me to run this Python file for me to seethe output of my code, I'm going to have tocome to the right hand corner right here andclick on Run. Now once I click on Run, yousee that it opens a new terminal automatically.And our code is going to be run in this terminal.So if we just wait a second, we're going tosee the output of this good. You can see righthere that we have a little word automaticallyprints hello world. If I say hello world,welcome. And I run it you see it changes andit says hello world welcome. So does how torun a Python file. Now let's talk about somemore features about this print function. Now,let's say we want to prints on a new line.Hello world, I wanted to welcome to be onanother line, we can easily do that, we canjust remove these. And then on a new lineby just going to print welcome exactly thesame thing. Now once I run it, you can seesays a logo down yet, and it says welcome,so does how to print on a new line, we canalso do a lot of things, let's say we wantto add another value to this hello world.Like, let's print a sentence, let's say myname is told me. And then I want to say myage is then I can add a comma right here andsay 100. So this will automatically tell Pythonthat this is a number, and is no more a string,just a normal kurata. So now once I run it,you're gonna see it says My name is Tony,my name is Andre, with no arrows. And automaticallyyou see the leaves a space right here, righthere, we didn't leave a space, by automaticallyonce we put this number year, it leaves aspace to clarify that if I put don't leaveno space, and I run it, you see that the spacesto do. So that's just a smart feature of Python.So I think that's gonna be all for the brainsfunction. Now let's talk about variables inPython. As you can see, I have three printsfunction. The first one says Tim is a boy.The second one says team is 18. And the thirdone says team is from Turkey. So as you cansee, in the three print functions, I'm repeatingteam three times. Now we can use variablesinstead of repeating a particular text. Nowvariables are just basically saving a datain the memory of Python. And then we can getthat data back by referencing its name. Solet's see this in action. Let's say abovethe code, I have a variable named name. Sothis name is the name of the variable. AndI'm seeing equals two, I put single quotes,and the name is theme. So name is the nameof the variable. And theme is the value assignedto this name. So like these, we've saved thisvariable up here. So we can print that wealso say print. Whenever we are printing avariable, we don't put quotes like we do whenwe are printing a normal string. So we canremove the quotes and just type the name ofthe variable which is name. So now when Irun these, you are going to see it printsall these. And on the fourth line, a printteam. It didn't print name. Now this is whatvariable is impulse is just basically savinga particular data and then referencing itdrew the variable name. So now instead ofsaying the same three times, we can just replacethis team with name. And for us to do thisright here you see we printed only the variable.And we didn't have quotes. We're right here,we're printing a string with quotes. And wealso want to print the variable with it. Sothis is called concatenation. We're gonnajoin the variable and the normal string together.To do these. Let's remove theme. And we'regoing to say name, which is the name of thevariable plus the remaining text. Now whatis the name plus is a boy is going to printus theme is a boy. So we can also do the sameright here. We just simply remove theme, Iwould say name plus is 18. We do the samefor the third line, we'll say name. Plus isfrom Turkey. Now once we print this, you cansee it says theme is a boy Tim is 18. Timis from Turkey. Well rightio said name. Sothat's what variable is about. So let's justtype CLS closes up. But variable is more broadthan just this. So there's something we calldata types. Now as you can see, this is justsim sim is letter is a corrector. And thatis a string. So strings are basically justcharacters. Now, string is a data type. Wehave if this is a number like 23 is no morea string is now an integer. We have Booleanwhich is for true or false values and oh Thisbefore this tutorial was going to be particularabout maybe two or three. So now, let me justundo that. Let me specify a new variable andname it age. Now this variable, I want itto be the age. Let's give it a team. So wheneverwe are using an integer or number, we don'tadd code when we are assigning the variable.You see right here, we added codes, and insideour code we put team, but for it to be aninteger, you will see that we do not add codes.If I over on these, you see dices 18 is in t, which stands for integer and then seemright here is a string. So now we can justjoin these by saying plus H. Now once we printthat is still gonna give us Okay, so you cansee now that this is can only concatenatestring, not integer. So now there is a problemwith Python. Anytime I want to concatenatea string with a variable, it doesn't, I mean,an integer with a string, it doesn't work.So we can just solve this instead of usingthis, we can say comma H. Once we press this,you can see it says theme is from Turkey.So let me close this up. Right here, we cansee anytime we're concatenating we just drinkit's possible. But when we are dealing withan integer, we can't use this plus, we haveto use comma. And we can also use comma, we'reconcatenating with a string also. So thisis the two things, we can use additional signwith only string. And then we can use commawith string an integer. So if I run it isto go to work theme is a theme that does basicallyout to concatenate and join strings with variables.Now we're gonna be talking more about strings.So strings are just plain text. So if I printsomething like print, alright, this is a string,string, or just plain text. Now we're goingto talk more about the features of strings,different things you can do with strings.Now let's say I say I put a full stop. Oh,you know, once I run this, you see that itruns it on the same line, which is I willyou wave, I want this to be on another linewithout being put in another print function,I can just simply we use a backslash n. Thisis a backslash n. Now this is gonna automaticallytake these to a new line, it's just like abreak, it's going to add a break in betweenthese and these. So now once I run it, you'regonna see he says, I, our you will have thispiece here because of this, if I can Sadatand I run it again, you're gonna see we haveI owe you. So with also prints drink as avariable. So let's see we have something namedname, and the name is Tim. So this is a stringis a variable, both a string type of variable.And then in print function, we also printthat string variable by just saying printname, without quotes. Once you print it, you'regonna see right here we have seen printedvisuals close this up. So if we come up here,we can also print let's say we want to adda double quotes or single quotes. Now youknow we can add a single quotes in betweenour text does because Python is going to seethis like we want to close on this printstext. So first we'll add the double quoteswe can just easily add the bus slash thenthe quotes now once you have a blog slash,and that's good, this court is going to printit as I run it, you see now we have I withthis good hour you so if you want to createspecial characters, we use the backslash,or you can just bring the backslash aloneis gonna work. So you can see the backslashis there. So we can print. Use them. Lastcrash to break to make it on a new line, becausethere is a backslash to add a quote. And thenwe can bring the bus slash just like that.Now let me talk to you about special functionson strings. So functions in Python is justa block of code, which does a particular task.So in this string string gets a lot of function,which does different things. Let's say wewant to convert all the characters in thisto uppercase, we can use a string function,we want to check if it's lowercase, or oncewe get on to the first letter, or the second,those are functions in Python. So now, wecan just say want to get only the first letter.Now once we get the first letter, we can justeasily do something like print name, squarebrackets, and zero. Now zero represent thefirst letter, if I say one, it representsthe second letter, if I said to representthe third letter. So in Python, or in programming,in general, numbers start counting from zero.So once I put zero and then run it, down here,you see it prints only t. Now let me run towhich is the third one, you see, it's printsonly M. And if I run what is not there, like0122, I try to run theory is going to giveus an error, index error. So you can see stringindex out of range, which means it's not present.Now it also do multiple things. Let's saywe want to convert these all to uppercase,we can just do name Dodd's case. Now oncewe run this, it says as no attributes or bycase, so sometimes we can run into error,we just change it. So I think is because thereis no supposed to be case. So named oppa isthe function that changes it to uppercase.So once I run it, you see now that we haveseen in uppercase, we can also do the samething with lower, we just say named or lower,and then we run it, now you can see that everythingis being changed to a lower case. Now oncewe come back here, we can also check if everythingwhich is present here is uppercase, or ifall the characters are lowercase. So for usto do that, we're just gonna say name.is,lower. So as I run it, you see it says false,so it's going to give me a true or false response.If everything is upper case, it's going togive me false, but it's lower is going togive me true. So you can see, since thereis an upper case t, I asked if it's lower,and it says false. But if I ask if it is upper,I run it. If this is false, that's simplybecause this upper case and lower case, noteverything is upper or lower. But if I changeit to a lower case, let me change everythingto upper m, and then I run it because thenicest true, because everything is uppercase,and they will also join different functionstogether. Now you can see if I say somethinglike is lower, and I run it, it says false.But I can first of all, convert it to lowercase,then ask if it's lower, so I can do that lower.And then run. You see now it says true. Whatis upper case. So first of all, it says nameddon't lower, which means converted to lowercase,then it checks if is lowercase, which givesus true. So that's basically how to just joindifferent or add different functions together.Along with also do something else by let'ssay we want to get the amount of characterswe have in this variable. To do the arts,we can say Len, then we open a bracket andclose it. When we run these, you can see itgives us three because we have 123 if I havea lot, and then I run it is going to giveme a team the number which we have in theso that's how to get the length of a string.But let me just undo that. But let's say wewant to find where at particular text ease.So this is i less than want to get the indexnumber of I, as we know this is zero, andone. So this i is index number is one, ifwe want to get it, we're just going to say,Len by going to remove Len. So I'm gonna sayname, dot index. And then we're gonna sayI, so now he's gonna print me one, becauseas the index number of I, once I run it, yousee, it's prints me one, which is the indexnumber. Now, let's say we want to replacea text, let's say we have m want to replaceit with C. So we can easily do that. We'rejust gonna say his name, the Replace, I'mgonna open a bracket, Bertha parenthesis,then the techs to replace will not replacem are gonna put M. And then what we just wantto do is comma, and then what want to replaceit with want to replace it with C. So now,once I run these, you can see it's printed,see it. So that is replacing this m with Tcode, that's basically how to replace. Sothere are also a lot of functions, a lot ofstring functions. But these are just shown,I showed you how to use them. So that's gonnabe all for strings. In this part, we're goingto be talking about numbers in Python. Soto print a number in Python is pretty easy.We just type print, and then we just go aheadand type the number 78. Now once we just runit, you'll see that it prints 78. So we don'tneed to add any syntax or anything, we justprint 78. And it gives us 78. Now we alsospecify a number, the variable can say, No,the number is equal to 79. We just write theletter, we don't need to add these. And thenwe can print number. So once you run it, itgives us 78 and 79. Now we can also add numbers.So let me just remove this. So instead ofjust printing 78, we can print 78 plus 22.Now we got add a number, we can perform arithmeticoperations. Once I run it, you see that itgives me 100, it automatically adds thesetwo numbers or integers together, and thenit runs it. I also try these with a decimalnumber is 2.7 days. Then once I run it, you'llsee it gives me 100.9 34. So that is how numberswork. And we'll also test it out with thesubtraction. Says gives us 55.066. And thenwe can test it out with the division givesus the answer. And then we can also test itout with the multiplication. When we run it,it gives us the answer. So that's basicallybasic arithmetic operation with Python, wecan go further just what we did with strings,we can go further and use the beauty numberfunctions. So let's say I want to show theremainder of a division. So let's say somethinglike 20 divided by six. Now you know thatthis will give us three remainder two. Sogonna give us three remainder of these. Well,what we would just only want to get the remainder,we don't want to get the main answer, we canjust do 20 percentage sign six, as I run it,you see gives me two which is the remainder.Now does how to get the remainder of a divisionwill also convert a number to a string. Nowlet me show you. Let's say we have this variable.We have a variable named number equals to55. You can see that is a number an integerright here. Then I can specify a new variable,I can name it number two, and I want thisnumber to be a string. So I'm going to saythis drink of number variable. So now, ifI over on this number two, you're going tosee that as a string, when I print numbertwo is going to be 55. But now we just shrink55 also boys a string. So how do we know ifit's really a string? Remember that when concatenatingyukako calcination numbers, wake up caucusneeds restring. So let's try to concatenate.So right here, let's see. Number is, let'stry to call continue with the main number.So let's say add number. Let's run it, yousee, it gives us an error can only call causein a string, not integer. So but now thatwe've converted it, this try to calcagni withnon to, once we run it, you see that givesus number is 55. So that's to show that ithas converted that integer or that numberto a string. Now Python sees that as a string,this is also very useful in a lot of cases.So does that. And then we can also get theabsolute value of a number. So let's say let'sjust cancel this, let's print minus five.Now, obviously, when we print, this shouldgive us minus five, as you can see down here,and just closes up. What if I wanted to printonly five regardless of the sign, if it'spositive or negative, I'm going to add a bs. Now this is a function is a number function,as I explained earlier, function is just ablock of a block of code, which does a particulartask. Now we can write a function manuallyby itself. But Python has some built in function,which you can automatically use. That's whywhen we use abs, it automatically sees itas a Python function. Now this ABS means absolutedoes the full meaning of ABS, so we're goingto get the absolute value of this number.Now when I run it, you see it prints onlyfive, regardless of this negative sign besideit. So we have four and two. So now you knowthat four is obviously greater than two. Soonce I print these is going to give me four,this is showing the is number of DS. So thatmeans for resupport to or not for is for usto serve. This means we have these two numbers,Max was going to get the highest number. Solet's say we have another number named three,once I run it is to print four, because fouris greater than all of these for now whatif I have 16 once I run it, it gives me 16.Because 16 is the highest number in this rangeof numbers, I can also do the same to getthe minimum amount of numbers, I can say mi n, so that is going to automatically printtrue because as the minimum so once I runit, you see it brings two so that's the basicway of getting the maximum and the minimumand then it goes around in number two. Sowe can estimate a number. So you know, innormal mathematics, if we have something like3.2 this is estimated to three, but if wehave something like 3.5 this is estimatedto four we can also do this year in Python.Suppose To do this we just a round the round3.2 is gonna give us three was we round 3.5is gonna give us for just normal estimation,rounding off to a number. And then we alsohave one, which is been let's see beam. Sowhat this being does is that it converts aparticular number to a binary string. Nowif you know binary numbers is this weird typeof text. So each number as is binary stringszeros it gets the binary string of a numberJust run it, and it prints this. Now let'srun something like 334. It prints the binarystring for 334. Now, that is some basic functions.But they are countless functions for countlessnumber functions. So all these, we're notable to assess them, because we are able toassess them because they're already builtin Python. But there are still more that wecan't assess. Except we input. Now there'ssomething in Python called inputs. Now wehave more number functions, the one that isable to find the square root, the one thatcan get the power, various countless. So nowthe reason why we can't access those one,because we haven't imported, the ones I justshow you, we can use them without importing.But the ones I want to show you now we needto import them from the Python mat functionbefore we can use it. So first to import,we're going to say from math, something likethis. import all voiceover writing Oh, right,esoteric. So what this is doing is sayingfrom the maths class, or the math function,import everything which is there. Now in thismaths class of fine john, it might, they mightbe the one that can find square roots, theymight be the one that can find the power,everything. So we don't know the one we wantyet. So we're just importing everything withthis asterik. So now we're going since wehave this imported, we can find the squareroots. Now, we can just see square roots oflet's do something like Andre. Now once werun this, it will give us 10. As you can see,give us 10. Today, this point 00 K, but nowit gives us 10. So that's gonna be all aboutworking with numbers. So in this part, we'regonna be getting users input. So what we'regoing to be doing is to tell a user to inputa text, and then we're gonna save that textin a variable. And then we're going to tellthe user what input. So let's go ahead andprotocolized that. So to use our inputs inPython is pretty easy. We're just gonna sayinputs, then open and close parentheses. Now,when is open or close parentheses, we're gonnaask the user what we want him to input. Sowe're going to put double quotes. And in thatcode, we're going to say something like inputyour name. So now this is going to tell theuser to input your name. And then once theuser type in something like theme, or Tommyor john, anything users type, we want to saveit in this variable called name. So now thisvariable called name is going to be the input.So now let's try that we run it. You see now,the first thing he says is input your name.Let me say to me, when I click enter, so nothinghappened. What does how to use our input today,just close, we can come back here and justsimply print to the user. Name. So let's runit. What is our input name? unsafe, Tim, yousee the eye just prints team. So we can makethis more interactive by asking for the user'sname. And maybe asking for the user's ageand then telling the user Your name is thisand your age is this. So we have we need tohave two variables. Second, the age. So nameequals input your name and then age will beequals input your age. So what we want toprint is, your name is and they just wantto add the name and they will close that.And they will say and you the age, years boat.Now when we run these, it says input yourname. Let me see Joan, and is 105 years old.So he says Your name is john, and you are105 years old. So this is basically how tojust collect simple data from the user. Andthen use it the way you want tell the user,your name is this your ages this. So thisis the basic concept. You can also link itwith how they do websites, like when you createa signup to a website. And then they savedyour name, your email and everything in thedatabase. And they later Do you welcome johnare welcome, whatever your name is. So justto link that concept is basically just gettingthe user inputs, and then storing it as avariable, in this case as a data, and thenwe can print it to the user back. So does,too. All you need to know about getting user'sinput will also make it more fun. Now, whenwe get user input, you can see that the ageis seen as drink, right, the Ice Age is string,but we want the age to be integer. So we canconvert this string into an integer. So forus to do this, we're going to say i n t, weopen the bracket, and then we close the bracket.So everything is inside this integer function.If I come back here, you see now that thishas been changed to integer normal strings.But now if we try to run these inputs, myname, I input a random age, you can now seeit gives us this error can only concatenatestrings, not integer. So for us to be ableto add age, you know what we need to do, weneed to either convert it to a string, whichwe know what to do. Or we can just use a comma.So let's just remove this. And then let'srun it. So let's input a random age righthere. random name, and age. So now you seeit works. It says Your name is john on your13 now does how to basically just get userinput, use it how you want, and then you canpass that information back to the user. Inthis part, we're gonna be doing a simple Pythonexercise. So what we're going to be doingis a simple world replacement program. Sowhat is going to be happening is that a useris going to input a sentence. And then let'ssay you want to change a word in that sentenceor change something in that sentence, thenwe're going to allow the user to be able todo this. So if a user inputs A sentence, likeI am a boy, and he later wants to change ourboy to let's say, a guy or something else.So that's what we simply want to do. So I'mgoing to ask the user for three inputs, thefirst input will be the sentence, the secondinput is going to be what do you want to change,and then the total input is what do you wantto replace it with. So let's get that on protocolizedit. Now the first thing we're going to dois just to have those variables. So let'shave a variable named sentence. And I wantthis variable to be an input. And then I'lljust say, and your sentence. Now, let me justprint the sentence to the user. Let's runit. Now let's say the sentence I am a boy.And he just simply prints that sentence. We'regonna come back here, let's just say your,your sentence is I am a boy, which is goingto be whatever the user writes. So then, whatwe now want to do is to have another variable,let's say what one should be an input. Nowthis variable is the word you use that wantsto remove or replace. And then we can say,and word to replace. Let's say the word toreplace. And then once we have that is goingto be stored in this variable named word one.They're also going to have another way, letme work through. This is going to be, whatdo you want to replace it with. So let's enterthe word to replace it with. So now once wehave all this, we're just going to print sentencedot replace. That means we want to replacethis with this open bracket to take two inputs,which is word one, the word wants to replace,and then word two, what we want to replaceit with. So what this is doing is that, let'ssay we have a sentence named I am a boy, thenthis word one is the boy wants to change,and then we're two it was one to replace itwith. So let's just go ahead and test it.So right here is running. Okay, it gives usinvalid syntax. That's because we forgot toadd a plus right here. Now let's do that again.Right here, you can see says enter your sentence.Now let me say I am a boy, now is bring tous your sentences, I am a boy. And it saysenter the word to replace so I want to replacethis boy and enter the word to replace itwith or to replace it with dude. Now you seeit's print, I am a dude. So that's basicallyhow to do a simple word replacement exercise.It takes in an input, which is a sentence,and then it takes another inputs, which iswhat want to replace. And then the third oneis what wants to replace it with. And thenit's basically just printed out to the screen.So I hope you understand what to do with deedin this part. If you didn't, you can justgo back and watch this part again, and makesure you understand before moving to the nextone. So in this part, we're going to be talkingabout working with lists in Python. So whenyou're working in Python, you're going tobe dealing with a lot of data, or you wantto be able to know how to feed your data intoa list. So the list in Python is basicallyjust a list of different attributes of differentvalues fixed into a value. So let's just divestraight into the protocol. Now to definea lease is similar to define a variable. Sowe can just give it a name of a lease, let'ssay, a list of countries, and I can name thelist of countries. And I'll just use the equalsign and the square brackets. When we're defininglists, we need to use a square bracket, Icannot give you some inputs like United Kingdom.I can also give it another lease like xe,Ghana, let me say Nigeria, let me give itone more value. And I can see Australia. Sonow this lists a list variable, it has fourvalues. So now once I print the list likethis, I'll just say print. And I give it countries,which is the least you see that he just bringsme the old list the way it is right here.So that basically the main thing you needto know when to find the list. By list ismore broad than this, there are a lot we cando with lists, like lists, I just want toget the first attributes. Now each list hasthe index number, like this is 0123. And soon, just the way I said earlier in this tutorialthat in Python or in programming, General,numbers are counting from zero. So the indexnumber of this value is 0123 is just similarto when we have a variable, let's say we havea variable named name. And we have to me sothese as an index of 0123. Now that's verysimilar to at least each value as an indexof 0123. Now we can just delete that. Nowlet's say we only want to print these we don'twant to print the whole list. I can just doit like these countries with square bracketsand are fixing the index number in betweenthose square brackets. Now when I run theseyou see now and that is brings me only UnitedKingdom. I can also do the same thing. Let'ssee how to print Nigeria. I give it to I runit now you see Do you have Nigeria, thereare a lot of things we can do. Now, let'ssay once we get this, we just want to bringonly n from it, we can also do that. So otherthing country's index number two, we can specifythe index numbers in zero. So once I run it,you see it Sprint's me and now what does thismean? It says countries gets the value withthe index number 2012. So now it has Nigeria.And then I say from that Nigeria gets me theone with the index numbers zero. And thenwe see in Nigeria, n as index numbers zero.So that's basically I'll just add some simplethings in Python, Python lists. Now let'ssay we just want to get only all the listsfrom Ghana to the end, we don't want to addUnited Kingdom, or we just want to get thelist from Nigeria to the end, we can alsodo that. So we just say countries want toget from Ghana to the end, we can just say,our square bracket, one and a column. Nowthis is going to get everything from indexnumber one to the end. Now let me show weclose this. When I run it. You see now itgives me the list without United Kingdom doeslt just get it from a particular index numberto the end, we can also do the same thingwe can see from to use it again, from Nigeriato Australia, right here, Nigeria, and Australia.Now I also specify a range. Let's say I onlywant to get the list from one to two. Okay,let me add one more value year, let me sayNew Zealand. Yeah, so right here, I say NewZealand. And this is 01234. Let's say I onlywant to get from one to three, I don't wantthe last one. And I don't want these, I caneasily do that, let's say from one, whichis from Ghana, index number one, that afterthe column, I'll say three. So 123. As I runthat, you see our K, it gives me Ghana andNigeria. So this is 0123. Okay, so let's saytwo, four. I, when I run this, it gives meGhana, Nigeria, and Australia. So it givesme from here all the way to three. So thisis basically going to get from one which westarted to the one before which we end. Sodoes how to do that in Python. And then wealso get the type of the list. Now if I printsomething like type countries. Now it's goingto print to me that this is a list down here.So let me just type CLS to clear everythingI've done. Now let me print it, you see saysclass lists. So this is showing me that thisvariable type is a list. Now it is just anormal variable as a string variable is alsogoing to show me that it is a string. Nowlet's try that. Let's just divert from leastfor a second. Let's say we have name. So meand I said that type of name. When I run it,you see down here it says a string. If I changethese to 12 you will see down here it saysinteger so does how to get a type of a particularvalue. So those are we know now that thisis a list variable. Now I can just simplydelete that. And then let's say I want tochange the value of one value in this list.Now let's say I want to change this from UnitedKingdom to United States. So what I'm justgoing to do is just say, countries zero becausethe index number of United Kingdom is zeroshould now be equals to United States. Andthen let me just add a print maybe print countriesnow when I print countries Okay, you see nameis not defined as because we've removed thisvery good I was gardening. So let's just removethis line. I run it again. You see now thefirst value is now United States. Meanwhile,his United Kingdom right here, but that'ssimply because we change it. The United Stateshere can also do it again, let's say we wantto change Australia, which is the third, we'llsay, three, unless they want to change Australiato a country like Canada. When I run it, yousee, we have the United States, Ghana, Nigeria,we don't have Australia, again, is not Canada,then we have New Zealand. So that's how tochange a particular value in our list. Now,let's say we want to get only the end of thislist. You know, we can also get it by justlet me just quickly delete all this, we canget New Zealand by just typing countries,which is index number, which is 01234, NewZealand index number is four by type four,and run it, it gives me New Zealand. But Ialso do it in another way. Now if I add anegative sign right here, let me delete these.And I say one. Now this is going to get theleast from the last value in that list. Nowif I run this, you see it gives me New Zealand,if I see minus two minus two is obviouslyAustralia. By run this now, you see we haveAustralia. So note that when you're usinga negative sign, it gets you that list fromthe last from the bottom, basically. But younotice that from the beginning, we use zerofor the first, and then we'll get startedfor the last we use minus one. Yeah, that'sbecause as we know, in normal math, zero isneither negative nor positive. So when westart from the back, we use minus one, notminus zero. So we start from the front iszero, we start from the back, it's minus one,so does how to basically use that. Now thereare also a lot of other things we can do withlist, like we can get the length of this list,let's say want to get how many values we havein this list, because most of the times youhave large amount of data can start countingthem one by one like these. But you can justsay le n countries, which is the name of thelist. Now once I run it, you see gives mefive, which is because I have five valuesin here. But note that when it gives me theanswer, it doesn't use me based on index value.Now index value is just like the ID assignedto each of these values right here. But whenI calculate the length, it gives me the actualamount we are via which is five variablesare calculated from the index number intobefore, I hope you understand that, we canalso do some other things like in the list.As you can see, all of these are strings.Now instead of printing strings, let me justdelete this New Zealand. Instead of printingonly strings, I can change, let's say thisGhana, I can change it to a number like two.So now we have the string, we have an integer,if I print these, okay, this gives me four.So let me remove length. Once I print these,you see, it gives me what I want to see, ifI bring the index number of these, which isone. And I press run, it gives me two. Sowe can mix different data types in a list.I can also change this Nigeria to true, whichis a boolean value. Once I run it, let's removethis. I run this, it gives me that so thereis not going to be error, nothing is goingto conflict, we can just easily do that. Andyou remember that we checked the type of alist. So right here, once I run these, you'llsee that it gives me class lists, which meansthis variable is a list. But let's say I wantto check the type of the values in a listlike I want to check the type of this valueor the type of this value. Now as you knowthis value is a string, it is an integer,this is a boolean value. This is also strings.Let me over on it. You see it gives me i nt which is integer on one side over on theseLet me see. k doesn't give me anything therebut this is a boolean value. This is a string.So let's say I want to get this, I'll justsay type country's square brackets, and Igive you this index number. Now when I runthese, you see it says class is a string.Let's say I want to give for the second one,which has an Indian's value of one. Once Irun it, it gives me integer. Let's try forthe third one. It gives me a bowl, which meansBoolean, so does how to basically get thetype of a string. And we can also do someother things like, let's see, the last thingI want to show you for this part is anotherway to define a string LMC to assign a string,I mean a list sorry. So instead of using thesquare brackets, we can also use somethingwe call lists. But now when we are using thislist constructor, is called the list constructor,it is used to construct a list, where I'mgoing to use square brackets again, we'regonna use normal round brackets like this.Well now, so let me just delete this line.Now let's use the list constructor to specifyhow to construct a new list. So I'll say list.And I'm gonna use normal brackets parenthesis,and it has to be double. So when I'm usingthe list constructor, it has to be doublelike this. Now you can have all my valueslike Nigeria, I can have the default before,I can have false, almost, I print these, wedon't want to print type, we just want toprint everything. country's nice, it givesme everything which I want to see. So doeshow to basically use the list constructorto specify a list. So we can print a listin two ways, the normal and the second listconstructor. And then we can also print themwith a normal way without lists like the squarebrackets, like these countries too. So now,if I said type, grants, the type of countriesyou see is gonna give me least. And then letme also print the type of countries to justto show that both of them are still lists,so lists and lists, so that it will be allabout the basics of list. In the next video,we're going to talk more about lists, attributes,there are still a lot of things we can dowith leastin this part, we're going to be talking moreon least, specifically, we're going to betalking about lists, functions, or least methodsin Python. So in the last part, I showed youabout lists and plenty things you can do atleast 20 list attributes. In this video, we'regoing to dive more deeper. Now let's say wehave two lists. The first one is list one.And this list one is just a bunch of numbers12345. And then we have list two. And thenwe want this list to to just be let's seea bunch of fruits so we have a banana andthen we have abuse men goes unless you'reEnglish. So now we have these two lists. Nowlet's say we want to join these two liststogether like we want to print it together.We are going to do something like list onedot append dot extend want to extend it withlisten to now also drains least one What isthis gonna give me is the these joint withthese. So let's print it. radiates you wantto drill for five then banana, Apple mangooranges. So just give me these joint withthese the first least joint with the secondlist. So does Wood stained doors, it combinesthe two lists together. But let's say we wantto add a value to the ending of this listlike oranges. Move on to add water, what dowe have? I think we have cherries, but wejust want to add something else to these.We can do something at least two dot append.And then what do we want to append to it,let me say cherry. Now we'll say print listtrue, you're gonna bring me all these withJerry. Now Jerry is part of this list willsee not only bananas, apples, mangoes, oranges,and it pains me cherry. Now if I see I wantto get the length of list two. Now we havefour year versus we appended one, it shouldgive us five. Now you see we are five. Sothat just see is a simple way to append avalue to a list. And it's very, very usefulalso. But let's say we want to put in a valuein between one of these, like we have multiplesin a value in between banana and apple. Thischerry, we want it to be right here, somethinglike this. Now if we want to do that, we'rejust gonna say lists two dots insert. Andthen this is gonna take two inputs, now it'sgonna take the index number, the index plays,we want to put it want to put it to one, andthen we want to put the ACE cherry. Now letme explain this further. So it says list twodots instead want to say in the index numberone, that means right here, then cherriesshould be right here. So 01 want it to bewant to input cherry. Now when I print Jerry,let me just run this, you see now we havea banana then we have cherry in between. Soin between bananas and apples, we have cherry.So that is how to insert a value in betweena list. But now let's say we want to removea particular value from the list, we can saythis to dot remove, alleges remove bananas.Now once I print list two is going to printme and list two, without bananas. And that'svery easy is just by saying remove, then whateveryou want to remove. But now let's say we wantto do something I want to delete everythingin this list want to clear it up, you canjust say least two dots clear. And nothingis gonna be in here. As I said at least twodots clear, this is going to be empty, it'sjust going to be an empty list. It clearseverything deletes all the values in the onceI run it, you see not I placed me on emptylist. So does algae just delete a list? Veryeasy. But now let's say that we have thesevalues. And the mango, we want to get theindex number of mango, as we know this 012.So the index number of Mongo is two. But wewant to get it let's say we have 1000s oflists of values in this list. Want to getwith the Mongo is located in that list, we'rejust going to say print list two dot indexof mango. So you just gonna print the indexnumber of mango. There's just run it righthere you see is these 2012. So it tells mewhere Mongo is located in this list, whichis very, very helpful. Now let's say we havea value appear in more than one. So we justwant to know how many times a value appearsin this list. Now it's very easy, we're justgoing to see is list dot count. Mango. Sonow it should tell us one because mango onlycomes in this list one time. Once I run it,you see here we have one. Let me come hereand input mango again. Now once I run it thistime, you see that we have to because mangois in our list two times. So that's how tosimply do that. But now let's see we havea list of numbers unless they are scatteredlike let's say we have one yeah And let mejust delete all these we have four, five,so we have three year. So 4351 unless I haveto at the end. So let's say want to printthis list in ascending order. You know, asI said, in Python, you might be working witha lot of data, and we have 1000s of numbersthat are scattered, I want to print them accordingly.Let's see from Andre wants to print to 250to 350, accordingly, not scattered, we caneasily do that was going to say, is leastone dot sought, like this, right here, I'mjust gonna print least one. Now once I print,it is not going to print it 43512 is goingto print 12345 in ascending order. Now yousee now we have 12345. This also is very usefulwhen working in Python. But now let me justremove this mango, we don't want to have ittwice. That was just for testing. But nowlet's say that we want to print a list fromthe back want to reverse the list. Want toprint it from the bottom, what we're gonnado, we'll say lists to dot reverse. It's veryeasy, we just released two dot reverse, almostto print list two, you'll see that it's printedfrom oranges, then two mango, two apples,and two bananas. Let's run it. Now I see oranges,mango, Apple banana models, how to easilyprint a list from the bottom from the lastvalue in that list. Well now let's say wewant to duplicate a list, like we want tojust take this list and copy it again or somethinglike that. Let's test the four lists to letme delete these two, let's have another listnamed list three less than we wanted to listthree to just be exactly the same thing withthis in duplicate of list two. So we're justgonna say is list theory can be equals tolist one. list two, I mean does copy. So justgoing to copy all the values in this too,and then paste it in history, I was referringto this theory, I run it, we have exactlythe same thing we get when we print listento this exactly the same thing. And then wecan also do something more fun. Like let'ssay we just want to delete the last valuefrom these I just printed everything else.We can do that by saying guys that by sayingthe pope method, so we can just say liststwo lists two dots, Bob. So when we say thestudent Bob is just going to remove the lastvalue we have in Dallas, it will delete isgoing to remove the last value we have inthat list, and then relive the rest. So whenI print these two now, if only three values.So now you see we have bananas, apples andmangoes, no more orange. But let's want tobe specific, we won't want to delete, youremember that we can those remove a valueby saying these two dots, remove an avocadospecify tlsa banana. And then when we printthis, it will remove banana. But we can justalso delete or remove a value by using theindex number. So in pop, we're going to saylist dot pop just like pop out to remove something.Let's remove the one with the index valueof one or say one and print us banana mangooranges. It gives us that same list but withoutthe value of that index number. But we canalso use doodies. Instead of using pop, wecan do this exact same thing. But now we canuse delete. So when we say d L, I will sayleast true. Let's say zero. So now this isgoing to delete the value with the index numberzero in this list two lists. When we bringlist two, they're going to give us everythingwithout banana. Let's run it nicely. We haveapples, mangoes and orange. I remember thatwe also showed you how to just clear lists,I will just delete everything in our list.We can also do this using this d l function.So instead of specifying something here, wejust say delete the L Listen to. Now thisthing is going to be clear this list. OnceI run it, you see it says list two is notdefined. Okay? But we do have list two righthere. So let's do something like, delete justone. Yeah. And then they just print. Oh, okay,so um, the reason why it says lists to notdefined, you can see we have list one, nothere we have list two, which has banana, apple,mango, and oranges. They were just doing withdeleted list two. So once we delete this listtwo is quite different from the one we didearlier, which was list dot clear. Rememberthat if we do list two dots clear is justgoing to remove everything here. But thatlist is going to be available in our code.But when we use this delete is just goingto delete a way that list is going to deletethat value. So it's not going to be in ourcode again, that's how I will not try to printlist to Python does it seeds, again is a listtwo is not defined, so it completely removesit. So there's a difference between the clearfunction and the Delete function. Now there'sgoing to be all four lists for now. In thistutorial, we're going to be talking abouttopples in Python. So topos used to storemultiple items in a single variable. So youknow least which we talked about in the lastbut topples are very similar to lists. Butthere are some basic difference, like tuplesare immutable. Now immutable means you can'tchange any value in a topple. Now let me showyou how to write a topple in Python. Now let'ssay we have a total of three numbers. I'llsay three underscore numbers. And I give thosenumbers, I want your writing the top, whichmeans a normal bracket, no square brackets,so 123. So let's say we have this now whenwe print three numbers around that, it justgives us this top bar, we can also do somethings like get the first value in that Tapuusing the index number, I can say get me zero,which will print us one. So we can also doall those type of things. But let's say wenow try to change the value of two to somethinglike 25. It's not possible because as I saidearlier on, it's immutable, which means wecan't change it. Once we have the top whodoes well is going to be for our code, wecan't refine it or add anything from the toplevel later in the code. So let's say we wantto do something like three numbers. Announcerfrom the index number one, change it to 23.And then I want to print three numbers. Nowthis is going to give us an error. So yeah,it says type error top object does not supportitem assignment. So he's saying what we wantto do top who doesn't support it. So that'sthe basic difference between topple at least.And then we can also do some other thingslike topples allow repetition of numbers orrepetition of values, like I have 123 uttanasanainput one again, when I just let me removethis line, I have one twice, once I printthat is going to work fine, it allows repetitionof the same value. And I also do some thingslike I can get the length of a toggle, I canjust say print le n and then it's just goingto give me the amount of values we have inthis top. As you can see it prints for becausewe have 1234 values. And then I can also getthe type just to make sure this is a top likea gundu type to know if this is a top or not.Once I run it, you see this class top. Sothat shows me that that is a top and top alsoallows various data types. Like I can haveanother top and see strings. And then I cansay oh lunch. Let me give you one more. Nowonce I try to print strings, you see thateverything works fine. So it allows varioustype of data types, we can also do it againfor like the Boolean type, I just say B Oh,and the less true or false, and then trueagain. Now when we try to print B Oh, yousee that it works fine. So it allows variousdata types. And then it doesn't just allowthem on separate variables, we can mix themtogether, like know we have one, I can haveanother one, which will be a string, whichwill be own. And then I can have another one,which is going to be a Boolean. So once Iprint the first one, we just three numbers.Now you'll see that everything still worksfine. So topples, allow all these kinds ofthings. And then in tacos, we can also checkthe data type of the value of that taco. Nowwe want to check the data type of this facevalue, we can say, type of three numbers withthe index number zero, which is the firstone, they should bring to us int, which isinteger. So as you see it says class int.Now does topple can also do that. Now, insteadof just writing these parentheses right hereare normal brackets or circular brackets,anything you want to call it is totally fine.We can also use the topic constructor, justthe way I told you about least constructorthere is also a topic constructor. So theonly difference is just our going to add apool right here. And it will have two bracketslike this, as I tried to print everything,still gonna be fine, let me just print thetop of variable normally. Now as I printed,you see there is still a top, nothing goeswrong. And that's gonna be basically all abouttopples the basics of tuples in Python, sowe might be using this topples less oftenin Python, who mostly use lists. But in somecases, we really want to use tuples. In Python,something like let's say you're working withcoordinates, or just some numbers that youdon't want to change, or some values you don'twant to change, I suppose might be the bestoption. In this tutorial, I'm going to betalking to you about functions in Python.So functions is just a bunch of code whichperform a particular task. Now functions allowsyou to package your code Well, let me sayrestructure goodwill is just like a blockof code, which performs a particular tasksthe way you want to use the function, youjust call it. So let me show you how to doa function in Python. So for us to definea function, we're going to use a keyword calleddef. Now once we type this def, Python knowsthat now we want to define a function. Soyou can say d f, let's just do a simple function,which is going to greet the user. Maybe itwill say welcome or something like that. Sowe can just say greetings. So now, the keyword, which is def, and then after it, wehave Greetings, which is the name of our functioncan say greetings underscore function. Sothis is the name of our function, and thenyou're going to be followed by open and closeparentheses, and then after it are going tohave a colon. So after this block of code,Python knows that whatever is going to comebelow it is going to be the task in whichwe want that function to perform. So onceI click enter, then I notice that it doesn'tstart from beginning it starts right fromdisplace, automatically it indents now inPython, indentation is very important. Sonow this indentation shows us that whatevercode we're going to write, let's like printsomething is going to be on the dysfunction.But if I just removed indentation, and I startfrom here, then the function is cancelled.This is an invalid syntax, because normallythere's supposed to be an indentation andan indentation, one indentation, it goes tofour spaces. So if I go here, you can seeis 1234. So once it indents automaticallyautomagically. That means it's created forspecies. Now let's say you are using a codeeditor which doesn't does the indentationautomatically Like if you're using Notepad,and then once you click on Enter, he doesn'tadd the indentation, you can just ask forspace like this 1234 that does automaticallyindented. So now we want this function tojust tell the user welcome or greetings fromme or something like that. So can you saywelcome user. So like these, this functionnamed greetings function is sprinting to theuser that welcome. But if I run this, nothingis done. I'm just closes up. And why is that.So when we have a function for that functionto be performed, or for that has to be executed,we need to call the function. And I will callthis function we can just say, Now, once Ipress enter, you see it's still indented.But I want to go to this function, I'm donewith what I'm doing in this function. So ifI just press A Backspace, now, this is outof this function. Now, if I just say, greetings,function with open or close parenthesis, nowI'm calling this function. So that means thisis girl is just the same thing as everythingwe have in this function. So now it shouldprint a welcome user. Also just run it yousee now it says welcome user. So that is howto use functions in Python. But functionsis more broad, there are a lot of things wecan do with function. Now as you can see,this then says welcome user the result. Butwhich user let's make it more fun, somethinglike that, we can pass in something calledarguments or parameters. So right here inthis open or closed parentheses, instead ofjust leaving him blank with compassion, somethinglike, Um, let's see, we have name. Oh, notthis. So name, which is the name of the user.Now, instead of saying welcome, user, wantto say welcome, name. Right here, we're justgonna say, name. And this is just gonna printwelcome name. But instead of name, it expectsus to pass in something when calling thisfunction. If I just run this, you see, itgives me an error. It says Greetings, functionmissing one required positional argumentsname. So this is showing us that when we'recalling this function, now, we need to passin wolves Eva user that is, so let's say thename of the user is john. So now when I runthese, right here, you see it says welcomejoin. So let me just go back and make sureto explain it very well. Right here we havethis function, it's having an argument orparameter, which is name. So this name isgoing to be able to tell the function whichuser it wants to greet. And then it's justgoing to greet the user with the print function.So for us to give it this name, this nameis just like a variable. So when we're callingthe function, instead of leaving these blanklike these, but I was going to pass in thestring like john, but you know, we can alsopass in other data types. So you can see thatthis john is a string. But let's say we justwant to pass in an integer or a number. Or,you know, anytime we're dealing with numbersin Python, we don't need the quotes, we canjust say 34. Once I run these, you see itsays can only concatenate strings, not integer.So if you follow this tutorial, from the beginning,I showed you how to convert an integer toa string. So right here, it says if count,concatenate string an integer, that meansyou can add them both together. So for usto be able to use these, we must make surethat we convert this integer to a string.So I'm just gonna say string like this. Nowthis name is a string. Once I run it, he sayswelcome pitiful. So that is how to basicallydo that. knowledges go back. So let's do makesure we're passing in john. So that is howto pass in parameters or arguments. Now youcan call it parameters. You can call it argument,whatever you want is fine. And then we'llalso pass in more than one parameter or argument.So we can pass in name can also pass in age.And then we can say welcome then the name.And then we can say something like let's dothese you typed the name, let's see, age.Yes board and a full stop. So right here,when we're passing in these, john, we're goingalso passing the age as an integer is C 27.But remember, now this is an integer. If werun these, obviously, we're going to havean error, which is cannot concatenate stringand integer. So you know that we now haveto convert this to a string right here. Andthen run it. So you see it says, Welcome,john, you are 27 years old. So does what doeshow to simply do that, you can pass in twoarguments or parameters. Now, let's say youdon't know the amount of argument that's goingto be passed in you. Let me particularizethat Before explaining. Now, let's say wehave names. Let me just remove all these this.Welcome name. So let's say we have these.Well, we don't know how many is going to bepassed in here. So we're gonna have to putsomething like esoteric. Now this asterikis showing that we're passing various amountslike a tuple, a topple of which is like alist of values we're passing in here. Andthen we don't know the amounts that is beingpassed. So let's say right here, we have thistopple, john. Let's see, we also have anotherone named, Tim. Let's give it one more. Okay,right here. One more named Tom. So right here,we're passing this tree list these three valuesa year as names. So these names is like atopple now, that's always a steric. Becausewe don't know. So for us to now show the name,which we want. Let's say we only want to greasethe second user, then we can create the userusing its index number. So you can say names,the index number is one. Now when I run these,you see it says welcome, Tim. So does howto pass in various values, more than one valueif we don't know what we are passing. Now,let's just go back. Let me press Ctrl. C,but to name and age. Quickly, okay, like these.Yeah. So let's print this and make sure thatour code is working. Welcome, john, you are27 years old. Right. Now, we can also passthis instead of just passing the values wecan pass is true, the variable names now catchesup to like name is equals to john. And thenage is equals to 27 is still exactly the samething. So when we run it is still going toprint those welcome, john, you are 27 yearsold, is basically the same thing. So let'smake this more fun. Instead of just passingout these values, statically, or by just addcode into values, we can first ask the userto give us an input of his name and his age,then we're just going to print that. So let'squickly do that. Right here. No, right. Yeah.So right here, we can see name, inputs, andyour name. And then let's give it anotherone named age. inputs, MSC and your age. Sonow asking the user for the value is one I'lljust type in these. And then once the usergive us these are those gonna replace thatyear? So by placing it with name, and replacingthis with age, so let's run this. So if Icome down here, ask for my name. I say team,it does for the age, I say 101. Now it sayswelcome team. You are Andre, our. So I hopeyou get the concept of functions in Python.These are the basic thing you are going tobe dealing with in Python. In this part, we'regoing to be talking about return statementin Python function. Now return statementsare just being used to get a response fromthe task being executed in a function. Now,as you know, in the last video, when we defineour function, then we just simply printedout whatever we want to return. But normally,in Python, we use what we call a return statement.So this return statement is gonna like giveus an output or give us a feedback of whathas been executed. So let's personify thisright, let's say you are, you are being sentan errand to go, let's get some information.And then when you come back, you want to givea response or you want to return like a feedback,you want to say what you want to get, or thetask which you executed. So that's the samething right here in Python function, decodeblock, goes for the errand, and in the returnstatement, give us a response. So let's showyou how to do that. We're just gonna definea normal function, let's just say my function.And then it's not going to take in any argumentfor now. So in Yeah, we just want to returnlet's say, five blows four. So this basicfunction now is just simply going to returnnine, because that's 5.4. But now, if we canjust print out my function, so once we printout my function, you see, well, it says function,my function is just you know that as a function,but we also need to add our open and closeparentheses, when I run it again, we see nine.Now we're gonna make this like more interactive,we can just have a function that adds up tonumbers or subtract numbers or something likethat. So we can say, add numbers. And thenwant to add two arguments, number one, andnumber two. So what we just want to returnis number one, plus number two. So right here,we can just passing no more number two, andnumber two as three s3. So this will giveus, you see, says my function is not definedas because we've changed the name to add numbers,we're just going to run it again. You see,now it gives those five. But let's make thismore interactive here. Let's say number one,is equals to input. And first number underlays,avinoam. to aim boots. And second number.All right, yeah, so same to give us numberone, right here we'll give is number two.So now when we run this is going to ask usfor the first number, let's say 80. Or let'ssay 20, as the second number is going to addthis up and give us 100. Now it is you seeit says 88 8020. And the reason why it saysthis is because it's seen these as an statusdrink. And so, when we use the addition isseen it as concatenation. So as I just said,8020, but I wanted to add you by coming outover very juicy says the stringed Well, weknow we are collecting an interior what Pythondoes, you know that so, we have to tell Pythonthat a what you want to collect is a number.So I want you to add it to do that convertit to an integer by saying i n t. Now, weclose it right here, then we also do the samething i n t and then we close it right here.Now, when we run this is going to add it forus at this 20. Now it gives us Andrea. Sodoes the basic concept of return statement.And I also want to point out something thatwhenever wisened return statement in Pythonfunction, we do not write anything after thatcode block. Like that return statement showsthe end of the function Call me an hour saveprint. Hello. Once I run it asked me for thenumbers, you see just gives me 80 just returnthese, it doesn't print a low, because itis outside our function and is not a normalindentation. So that's code is not seen inour code block. But if I come here, if I deleteit on inside the function, I paste it is goingto print that for us. So let's say for fornow you see we have Hello, and then we havethe answer of the audition. So that is howto use return statements in a Python function.In this part of the tutorial, we're goingto be talking about if statements in Python.Two if statement is basically just givingPython a condition. Now, this concept is veryeasy to grasp, not only in Python, but inprogramming in general, there is always ifstatement, but maybe with different syntax.So if statement is just a line Python to executecode automatically by itself. So assumingthat if a particular condition is true, thenPython should do this. But it is not true,then Python should do that. So why does giveme Python a condition before it runs the code?So let me first type a simple little notesso you can understand the concept. So I cansay something like if I write a number, sonow I write a number. And then if the numberis divisible by two, then we know that thenumber is an even number. What if is not divisibleby two, then it's an odd number. So somethinglike this, this is not how to write code.This is just plain text. But I'm just showinglike yeah, use I wrote a number, then if thenumber is divisible by two, then we can tellPython to tell the user though, okay, thisnumber is even. But it is not divisible bytwo, then this number is odd. So now let'sprotocolized is on his right, it's a realPython code. So now we have a variable nameda is equals to true. And then we have anothervariable named P and b is equal to three.Now go have a simple if statement. checkingif two is greater than three or three is greaterthan two, or if variable a is bigger a variableb. So say, if a is greater than b, then wecan just print to the user a let's go catenateis greater than B. Okay, boy, yeah, we knowthat b is greater than a. So let's just makethis greater. So cool. We run. Now let's runthis. Now you see cannot concatenate string,I know those types of stuff. So let's justconvert it to a string. So let's run thisagain. You see now it says four is greaterthan three. So we checked if a is greaterthan b. Now it also check, obviously, if bis less than b. Now you see that nothing happens.Because we said it should run this code. Onlyif a is less than b versus is not less thanb, the good news a cuted. Now we can alsocheck if A is the same thing as B. So if bis equals to B legends make a equals to B.And we run it. You see it says four is greaterthan four because that was the third issue,say, but we can just simply say A equals B.So as you run you see is this A equals B,where we change is now to three. Now fouris no more equals to three. It doesn't run.So that's the basic concept of if statements.I will also do this for different data types.Now let's say we have a string, which is TeamB is also team. So now we know that A is equalsto Team A, B is equals to team. So obviouslya is the same thing as team. And then yousay A equals to B. When we run it, you seeit says A equals to B, then we can also usethe Boolean. So let's say true. Now we cansee if a is equals to true, that means ifA is true, then we can just simply say, Ais true. And then we can just run this. SoA is true. So does the basic concept of anif statement. Well, you know, we can alsosay if A is not true, that means is somethinglike false. They will say a is not true. Soyou know now is false. When we run it, hesays he is not true. We can also add two differenttypes, like if let's quickly change this backto integers. So let's see, if a is greaterthan or equals to b, so you know, a is greaterthan B. Or if a is greater than or equalsto B, then we'll say ratio say true or somethinglike that. So let's run it, you'll see saystrue because A is greater than B. And if ais also equals to B, it resists a true becauseA is equals to B. But now let's say a is lessthan b. When we run it, nothing has been executed.So now we want to add more functions to thisif statement. So it says if a is greater thanor equals to b, so let's just check if A isequals to B, no, say A equals B. But whatif a is not equals to be watching the Pythontwo? What should the cause do? Surely Joe'snot run anything? So we can now add else thiselse means if a vigils correct this, if Ais not equals to this, so as an IF is equalsto B it should print A equals B else meansanything except that, then she just printa not equals b. So if a is equals to B bringthis, then else means if it's not the oppositeof that, then issue just print a is not equalsto B. So when I run these now it prints ais not equals to B. So that is how to usea simple if an else statement. We can alsodo that with like a Boolean, does make thistrue. So say if A is true, let's say A istrue. If not, let's say not true. So whenwe run it, you see says A is true, with ourchanges to false. Obviously a is not true.So it says a not true. So that's how to basicallyuse a simple if else statement will also gofurther. Now let's say want to add more thanone condition, like if A is equals to trueleaf a is equals to false. Print A is false.Else is known of the two. So if a is equalsto true it should print A is true. A leafmeans require adding another statement isthe same thing as if both else if does meanyou have if so if a is not true, then youcannot check if A is false. So if a is falseprint this bereave is none of these two, thenjust print a is none of the two. So now itshould print a is false when we run it acrossYou will see a is false. now know how to adda simple elsif statement. Now we got add anyamount of Elif statement want to add, we cansay, Canada when I say leave a, let's seenot equals to, let's see. A something likethat, then we can print we can just bringanything wants to do. So it got any amountof Elif statement is, does the basic syntaxand we to use an if else statement. But nowwe can make this more, we can step up a little.Now instead of saying if A is equals to true,so we can say, if A is okay, let's let mespecify a variable, let me see. Boy, is true.Let me say short, is also true. So I can sayif boy is true, then print is a boy. Now,since boy is true, right here is nothing likethat. So let's just change this to boy, sinceboy is true, then we can say is a boy, wecan also do something like if boy is true,or shorts is also true. So that means if anyof these two conditions are true, you willprint is a boy or he is shot. So when I runthe AGC is a boy or he is short. So sinceboth of these are true, his prints this, ifthis is false, it still like he was saying,If boy is true or short is false, is stillgoing to print this. Now the reason why Istill printing this is because all we're raisingthe O is going to check for only one. So ifone of these condition is correct, he justruns this. So when I run this, you see isa boy or a short, both, if I change this nowto and you see that it doesn't print this,it will print a is none of the two. So let'sjust remove this else if for a while. So nowyou see that it prints the L statement a isnot only two. And that is because we're realizingand it has to check that these these conditionsare both correct. So if one of it is not correct,is just going to go to the next statementand skip that statement. So that's differentbetween all and and so now that we know theconcepts, the basic concept of if else, andElif statement, let's just go ahead and dosome simple exercises. Now let's say wantto use FL statement to check for the datatype. And until the user Okay, these datatype is, let's say a string, or it's a lease,something like that. Now, first of all, let'sdo the user to input something. So let's sayvalue should be input. And they will tellyou user inputs of value. Now once user inputa value, we're gonna check for the value andtell the user that oh, this is your value.So we can use an if statement for that. Sowe want to check if the statement is a string.So we can say if type. If the type of valueis equals to a string, str, then we'll print.Let's just print out value value is a string.Well, let's add an Elif. Let's say we wantto check if the type is an integer. type ofvalue is an int does an integer, we will printvalue is an integer. And then we also wantto check let's see if it's a list to say aleaf If the type of value is a list, do printSee, value is a list. Ball is none of these,we just say, we don't know. So right here,I wanted to add this, but obviously it says,Python says I've closed it. So for me to addthis calendar codes there, I have to use thebackslash. So now once I use plus slash isgoing to be printed with it. So now we cansay we don't know the date, I have the measuresor whatever they use our routes of value.Now, let me just close this quickly. And thenlet's test this out. Now we input the value,let me input six is this six is a string doesnice to year. Now the reason why this is astring, because anything we put automaticallygets it as a string. Now, if we want to getthis as let's say an integer, we have to typeint, we have to convert it to integer. Sothis type of exercise only works for string.So now we're changing the name of this exerciseto check in if it's a string only. So whatwe just want to do is we cancel this, we'renot checking for age or list or any otherdata type, we're just checking if it's a string.And that's because Python automatically seesit as a string. And we have to convert itto an integer if I don't want to know if it'san integer. So we can also go for that tocheck in with an integer by using some complexif statement, or some reg x we usually don'tneed to bother about for now. But for now,let's stick to this basic exercise. So we'rechecking if it's a string. So if the stringwho says the string is not to say, is nota strange. So we just bring all these to thetub. So right here is where it should be ifa space and then there's run it again. Nowwhen I print the value now, and I say, I knowyou can see that I guess that is a string.So that's basically how to just, you know,do it. But if we want to, like change it orsave and say integer. So now anything we inputis automatically seen as an integer. So itwill automatically say value is not a string.So even let me pull six. Now I say Conococut, nice drink. So that's simply becausewe have to convert this to string before concatenating.Or, let me show you a better way to do it.Since we're just dealing with one. Insteadof using plus here, I can just use a comma.So when I run this, again, I input an integer,he says seven is not a string. So now thesecond is a size we're going to do is to checkif a number is divisible by five. So we knewthat we have numbers, multiples of five, orsomething like that, that means the numberswhich five can be divided by So we have fiveitself, we have 10 1520, where we give youlike 17, we want to tell us that 17 cannotbe five cannot be divided by 70, somethinglike that. So we're just gonna automaticallyget an input First of all, and make sure it'san integer. So we'll say inputs a number.And then we'll see if there's just a gay,what wants to see now is that if the valueso what this is doing is add value is basicallythe number the user input. And then this percentagesign means the remainder. So we'll say ifthe user input 20, so 20 divided by five isfour, then the remainder is zero. So whenwe do something like 2025 in Python, it meansgive us the remainder. So first of all, letme just cut this out. And let me show youwhat that does. So if I say print 20 percentagefive, now you're gonna see that it's goingto print zero is going to print the remainderof that division. When I say print 22, itshould print me true, because 22 divided byfive is four, then the remainder should betoo noisy, right? Do we have to do them justquickly bring that back. Right now we're sayingif the value percentage five, that means ifthe remainder is equals to zero, then obviously,that just means that value can be dividedby five else value can not be divided by five.So since we're using an integer, let's adda comma here, like this. So this should work.Now it gives us a number, let's say Andreanow says Andrea it can be divided by five.Let's run this again and give it a numberthat can't be divided by five like 106. Hesays 100 and sees cannot be divided by five.So that's how to build a Basie program withJack's even number can be divided by five.Now the last exercise, which we're going todo on FL statement is going to be the exerciseto check if the length of a sentence is lessthan 10. So again, we're going to collecta value, but this time, it shouldn't be asdrink, because it's going to be a sentence.Now, once a cake if the the length of thatsentence is less than 10. So if the lengthof the sentence is less than 10, they willsay value is less than 10. Else Z value isgreater is more than j. So gases lead to thislist typing random things like my name ismy name. Now this is obviously more than 10.I eat enter, he said not supported betweeninstance. So because this is not seen as aas an integer, we can do this. So right now,anytime we are using this less than or equalsto, it has to be as does basically be an integer,we can do less than or equals to four string.What are some other ways we can do this, we'regoing to talk about seats. We could have solvedthis now. But I'm leaving this to for thetutorial, because I don't want to jump insome steps. So for any tutorial, we're goingto come back to this exercise and I'm goingto show you how to do this with strings. Butfor now I will be get the concept of use anelse statement. So before we continue withmore concepts in Python, we just want to doa simple Python program with Jack's even numberis an even number or an odd number. So aswe know an even number is a numbers we canbe divided by two, an odd number is the onewhich count. So this shouldn't take us upto like two minutes to do. So I'm just goingto call it an input from the user and nameis number we'll say input will say and a numberand then want to make sure that these is aninteger. And then we're going to say if numberpercentage two is equals to zero, then obviously,this is an even number. So what this is doingis that if the remainder of number dividedby two is equal to zero, then is an even number.Else. We just see, odd number. Now when werun this, we put the value of licence to cease.Now since this is an even number, we run itagain on the booster to 767 is an odd number.So does also do a simple exercise. sighs likethat using if statements in Python. In thistutorial, we're going to be talking aboutdictionaries in Python. So dictionaries areused to store data values in the key valuepairs. So dictionaries also data type, justlike least just like strings. dictionary isalso a data type. But this dictionary storesvalue in a pair of keys and value. So justlike a main dictionary, like an English dictionary,where we have the word as the key, and thevalue as the meaning of that word, so that'sbasically our dictionary works. Now dictionary,D are changeable, which means you can modifythem even after like configuring assigningthem. But they don't allow duplicate, notliking lists are tuples, that you can typein a value more than once in dictionary, youcan do that. So let me show you how to writea dictionary in Python. So let me just namethis dictionary, my gait, how to write a dictionary,we're gonna use these curly braces, and thenwe're gonna give you the key. So the key mightbe something like, name, and then I'm gonnause this column. And then the value can besame. And then I'm going to put the comma,I can have another key and value in, let'ssay, age. Unknown, let me say something likenationality. I can see something like Africanor something like that. And then let's justhave these two. Let me give it one more. I'llsee qualification. Let's see college degreeor something like that. So this is a basicdictionary in Python. Now, let's just startwith the basic thing by just printing thisdictionary to our screen was this. Let's justprint my dict. Now once we print this, yousee that it just gives us the dictionary nametheme as now the African qualification college.But now let's say we just want to print onlythis name, value, what to print the valueof this name. So this is the value and thisis the key assigned to this value. That meansif we want to get this value, we need to searchfor this key. Just like when you go online,and search for meaning of order, meaning ofanything, out of words, meaning of anything.So play, for example, meaning of order, soorder is the key, then the value you are lookingfor is the definition. So does our dictionarywork is very similar to the normal word dictionary.So now once you get the value of this name,we can just use the square brackets afterthese n in the same name. So what this isgoing to print for us is team right here youcan see team, which is the value of this name.Now there are other things we can do, as Isaid, duplicates are not allowed in, in indictionary. So now let's say I have two names.And the other one is john. Now when I triedto print these, you see his prints only thefirst one, it doesn't say I mean prints onlythe second one does the most recent one, it'sautomatically because this one out of it nowdoes what I mean by duplicate not allowedin dictionaries, you can't have two t withthe same name, we can have two values withthe same name. Now what I mean by that isthis is the key This is the value. So twokeys, we can add them with the same name bookI have two values. Let's say this is namedtwo. unnamed two can still be the same. Nowif I print these, you will see that name issame name two is the theme. So we got outthe values the same we can repeat that. Butthe key being assigned cannot be repeated.It cannot be a duplicate. Now let's say wewant to get the length of this And it is veryeasy to get just seen Len. Like this, thenonce we print you see tells us for that becausewe have four keys and values in here. Andthen we also mix data types. Now you knowthat let me just remove this, do you knowthat this name, the value been assigned toit is a strange devalue, besides the nationalityis also a string, and the value been assignedto qualification is also a string. But wecan change it, let's say want to add likeage, and we know that age will obviously bean integer, we can just add it here, let'ssay it's a seven. Now normally, we will writean integer without the quotes that are goingto write it in there. And then once we print,we can still go ahead and print. Ah, it'sgonna print into cell phones with no problem.can see it right here at seven, we can alsoadd a Boolean, we can say is tall. So it stillcan be true. And then once we print age, Imean wants to print my dictionary. So yousee it's print true. So it tells us that okay,this person is talk. So we can add differentdata types. And then what is very cool isthat we can also add a list, so we can listof his friends. So can the data type as alist like this, so we can see, one of hisfriend is Peter. We can say Paul, we can seeprecious and odd, so lightyear wants to printfriends. Just gonna print those at least.Okay, right here, it says invalid syntax error.And that will because we forgot to add a commaright here. So we should make sure to adda comma before adding another value. So oncewe click enter, you see it gives us PeterPaul, and precious. So now let's just bringthe whole dictionary without anything attached.Now we go down here, we see that it printseverything named team on everything we needto know about that dictionary. And then, tocheck if this is a dictionary, we can alsouse the type. So also, just put type hereis going to print dictionary for us. So youcan see right, yes, this class is dict, whichmeans that these is a dictionary. So we canalso make it more fun. By specifying a variable,let's say we have a variable named x. Andwe want this variable to be equals to oneof the values of this. So we can just simplysay, X can simply be equals to mod. My D.Name. So x now is name. Now once you printx, obviously it prints the name. Now, thoseare busy dictionary functions and dictionarymethods. So I hope you get the concept ofdictionary in Python. This tutorial, we'regoing to be talking about why loop in Python.So while loop is a Python feature, which allowsyou to loop through a block of code, whilea certain condition is true. So let's sayyou have a condition like if a number is greaterthan 10, then it should just loop througha bunch of code below. So just like a functionwith an if statement or something like that.So we are giving it a condition that underage, we have a bunch of code which we wantto loop through. So let me just show you howto use while loop in Python. So first of all,we can specify a variable named I can sayis equals to one. And now to use a while loopwe can say a while. One is still legs downsix. So this is a condition we're saying aslong as one is less than six. Then we justwant to print I I mean as long as i is lessthan six, not one is this very good. Thatis still one that we want to print, I andthen we just want to increment i by one Sowe can see i equals two, i plus one. So thisis just gonna run this while loop, as longas one is i is less than six, it's just gonnaprint it to the screen, and then it's gonnaincrease it by one, then run it again, runit again, until it makes sure that it doesn'tpass six, it doesn't reach six. So you canalso increment these by typing, i plus equalsone, the same thing, anyone will walk. Nowwhen we run this, you see now it is 12345.So what happened was that is loops throughthis block of code. So we said while i isless than six, so that means it should moveto this block of code the printed I, thenafter that we incremented it, there, now iis equals to two is still less than six. That'swhy we have to, then it did the same thing.incremented it we have 345. But after five,it did the same thing. incremented by one,but now i is equal to six. So because that'sthis condition is really false, is no moreless now seeks then the wild loop to stop,you just like caught in a way from that wildloop. So that's basically what while loopis about, it's very important in Python, thereare a lot of Python programs, you want tobuild that we needed to use a while loop toloop through different things with a condition.And then you can also do more things likee while i is less than six, or i is equalsto six, something like this. So now you knowthat when we run these, it should print those126. Because there's no more just only wheny is less than c so so when is equals to C.So now it gives us an error, because whenwriting equals two in Python, it has to bedouble. So let's run it again. So now yousee 123456. So why loop in Python loops througha block of code at a certain condition beingtrue. So because this is true, one of theseis true. It just prints I increase it by sixcomes back does looping does that code again,increase it by six come back, and then itmakes sure that it goes to six. Now go. Sosay i equals to 10. Once I run this, it givesus 12345. So if we say and and now we runit, it doesn't give us anything. So sometimesa wide loop. I put this in why loop conditionsis not similar to if statement, you know,when you state where we can do Eva is lessthan six and is this, then you should do acertain thing. So now you can see that ifi is less than six, and i is equals to 10.So the reason why this didn't run is becauseat first i is less than six. So that's youdrawn, but we'll say and it's mostly equalsto 10. But we know that i right here is notequals to 10. So if I change this to 10. Itstill won't run. And the reason why it won'trun is because one of these is not correct.So I is not less than six because 10 is noless is what we say is less than 16. Now,then we can run it, I guess see it's printsomething now. So why is he and all in thecondition? Where is he Oh, as long as oneof it is one of the condition is true, thenthat while loop we run both way. And the twoconditions must be true before that, why docross so now they just don't bother aboutthe and and now let's change to one less changesto 10. So now when we run this we should get129 let me just expand this we see that wehave 123456789 now this is basically the basicconcept of why loop in Python. In this tutorialwe're gonna be talking about for loops inPython. So follow disease for iterating overa sequence. Now this means is used loopingover a sequence. And this sequence can eitherbe at least a tupple, or dictionary, evena string, a range of numbers, it can be anythingthat is a list. Now we use for loop to loopthrough them. Now a for loop is very usedin Python is used a lot in Python, actually,because most of the times we have lists ofdata we have data, large amount of data nowfor loop is used, again for loop to loop througheach amount of data each value in that data.So let me just show you how we do a for loop,or we call the for loop in Python is veryeasy. Now for you to type a for loop, thefirst thing you need to do is to type thisfor keyword, fo R. Now this keyword showsthat we want to loop through something. Sowe can see four letter in four letter forletter in. Let's say something like, hello.Now this is a for each letter in ello, whichis h e l l, we just want to print a letter.Now when I run these, you will see the experiencehe differently, it brings everything separately.So it's looping through each letter in thatello string, like iterating through the sequence.Now we can also do these by having a list.Now you can see my lists, I would get up thislist to be anything ledger, C, gi j Yu GiOh, now we can look through these and sayfor, let's say like for x. Now not that thiscan be anything, let me just this in whichI put later it can be denoted by anything.It can be represented by anything. So whenI first got started with Python, I was kindof confused in this for loops, just simplybecause of this letter. So I thought thatyou know, we're since we're using a low, andeach is called kereta. Ages got a letter isgot a letter, so I thought we have to uselater for each. But now I just want to clarifythat so that nobody will have to go to thatconfusion. So this can be denoted by anything.If I say four eggs in a row, and I just sayprint x is going to do exactly the same thing.If I say for gi or for anything I do, it canbe denoted by any single thing. Now let mejust so now I just want to say four items,or four values will be better for values inthis my least. So I'm going to remove thisstring as in my list. Now I just want to printboth values. Now once I press run, you seenice prints everything j ij Yuju, which isgi JU and J. So that is basically how to justloop through a list. Now you can look throughanything, actually, you can look through adictionary, so they just have a simple dictionary.And then let's say we have curly braces, andthen we have name. JOHN, we have age the thingthat I just leave those two. Now you can seefour values in my date, print values. Nowas I bring these you see it says name, age.So you just basically sprint, these two whichwe have name and age. So that's iteratingover words over a list of values. And thenin for loop. There's also something we callthe break. So now let's go back to our list.Just Yeah, so now we are we still have thisor at least I would say four values in mylist print values, but I cannot see if valuesis equals to Jeju then I want you to break.So what this is going to do is that it's goingto look Do it one by one, it goes from j i,then he goes to J au. So I've seen, once itgets to this j, you It should break, thenyou should stop that loop. So once I run these,you're gonna see, okay, right here is supposedto be double. Once I run these, you're gonnasee Justin j, i and j U. Now, why is this,I said that it should continue looping bringsall the values, but once it gets into thatvalue is equals to j, u, m is once in a loopto this j, you then break, break me stop theloop. So that's why I want to get to J, youit stops, does Oh, we don't have j Oh, righthere. Now, we can also, instead of havingthe break here, I can do something like this.So even before printing values, I can havemy if statement. And I can say, for valuein values, if value is equals to j, u, I cansay break. And after that break, I can printvalues. So if you haven't gotten by now, thedifference is that if value is value, so islooping to these values. But if the valueis value, it should break. You know, in thelast time, it first printed value, if as Peteris Jay, you before it's broke. But now, ifvalue is J, you should break before even printing.So it's gonna guess that Okay, we have j youwant to break, then we're going to print soPython runs code line by line first runs thiscode and runs this then runs this, then likethat. So the first thing he sees is that weare checking if what want to look to nextis j U. And we see that yes, it's true isj U. Now we just break, then after breaking,we print values, so the only value I wantto print is G because we're broken when wego to you. So when I run these, you see thatI only have gi we don't Prince j au again.So that's basically how to use the break infor loop. But we can also loop through a rangeof numbers. So let's say we have 4x in range.For now, what I can just do is to print x.Now once I print x is going to give me a listof number from zero to three. So it's gonnagive me a range of numbers starting from zeroto the non last number before four. So I alsochange is only like 10, you're gonna giveme from zero to nine. So as you can see, itgives me from zero to nine. And then we canalso specify for each to loop through a particularrange of number. So now we're given 2010.But we can say each loop for each loop fromthree to seven, or from 10 to 70, or any amount.So if we wanted to loop from three to seven,is our going to do it, we just say for x inrange three to seven, look to this number.So when I run these, you see it gives me 3456,it doesn't start from zero. So it looks fromthree all the way to this seven. And that'show to loop through a particular range ofnumber. And the final thing I'm going to showyou in for loop is that we can also use theelse statement. So now let's just loop tofor a range of seven. So after looping, wecan see else, what this else does is thatonce this loop is done, once it's finished,we can just print finished looping. So nowonce I run this sprint from zero to CS, andit says finished looping, so that's what thethe else statement does, is that it just simply,first of all finish the loop first of allfinished iterating over the sequence, thenit just tell us whatever is in the L statement.So that is an introduction to for loops inPython. In this part, we're gonna be talkingabout 2d lists in Python. So to do lists alsomean two dimensional list. So it's like well,we have multiple lists inside a list variable.So right now we can have a normal list likemy list which can Just a numbers like 1234I was reprints my list, know that we're gonnaget 1234, which is a normal list. But nowwe want to have a to do list, first of allis recommended to press Enter just to organizingthe rotation, then we're gonna have a list.So this can be 123. And then we can have anotherline, which can be 456, then we are they'vecome up on another line can be 789. So nowthis is a to do list, because it has rowsand column. This is obviously a list in alist. So dislike the high level list and hislike his sub sections or something like that.So now once we just print my list, you'llsee that I just give us this normal list.But let's say we want to get this value ofone or two. So we're gonna get it using theindex number. So we know that the index numberof this is one of zero, which is the firstone, then we also want to get the face value,which would be zero. So once we print thisout, you will see that we have one. But let'ssay we want to get the value of five. So weknow that the index number of this is onethat was indexed number five, it's also one.Now once I run these, you see now that I havefive. So that's basically navigate on likebrains, or get some certain values from your2d lists. And then we can also look throughthese. So I'll introduce you guys to nestedloops. So nested loops is where you have aloop in a loop a for loop to be specific whenyou have a for loop in a for loop. So now,instead of just printing, let's just say forsomething like lists in my list, they initiallyjust print my lists. Now as I run these, yousee just print my list, have one list in mylist, it just loops through that. One, insteadof just looping through this or just printingthis, or I can do is I can add another forlooping the so for least in my list, and Icannot see for maybe the rule or the columnfor row in lists. Then now we want to printrow. So when I run these, it gives us an arrowdoes because in Python must have indentationto show that this is on the DCE. Let's runit again. Now you see it says type objectis not iterable. So for row in lists, mustmake sure that everything is intact. So Iput the list, but the name of this is lists.So after that is now when I run this again,you see it gives me let me just open thisup. You see it gives me from one to nine,which is every single thing via 1234 all theway to nine. So that is how a nested loopswork. So is like looping through a loop already.So a loop in a loop. But I have not triedit before. But I think we can also have anotherloop again on looping through something likeYeah, yeah. So there are various things youcan try out with Python is very great. SoI hope you understand the basic concepts ofSudhi least are nested loops. So in this partof the tutorial, we're going to be talkingabout comments in Python. So comments is beingused to prevent a particular code or blockof code from running with your actual program.Now let's see we have print. Hello. And thenwe also have print one. Now when I run these,you're going to see brings a low one. Nowif I call me and I put an ash tag, right besideD Like this, you see that this is grayed outis no more part of our code, it's still there.But when I run, it is not going to be wrongwith our code, the only one prints. So that'swhat comment is for, mainly in Python commentsis are mainly programming in general, is useful,explaining our code or is useful, taking downnotes in our code very well, like making ourcode more readable. In Python, you can alsojust add comment, let's say you just wantto quickly test your code without a particularcode block, you can also use comments. Soyou can also add comment at the end. Likeyou can see ashtag this line prints Hello.So you can just use it to explain your code.Or you can just use it to block the code fromrunning. And as you seen, if you're two commentsmore than one line, you can put hashtag onthis line on the second line, then everythingwill be commented out. But there's also abetter way to do this in Python, you can justeasily add the let's say you have a code block,or you have a function like my phone, Shawn.And then this function just prints. Hi, nowlet's say you just want to comment out thisparticular function. Now what you're goingto do is above of the function, you're goingto add three quotation marks like this. Andas you can see, it automatically commits allyour code out. So if we run these now, nothing'sgonna run at all. It's, it says we have asyntax error and stuff like that. So we haveto close these comments by putting those threecodes back on there, we'll want to close it,so want to close on the beginning of thisfunction to the end. Now when we run these,we will see that print ello and print onerun. So now we try to execute these by seeingmy on scarf. You see, that's gonna give usan error. It says name error is not defined,now means it doesn't even see this part ofthe code will define the function when wetry to run it, it doesn't work. So that'swhat comments are used for in Python, mainlytwo things useful removing your code, or judgesor taking notes or making your code more readable.In this tutorial, we're going to be buildinga basic calculator using Python. So we'regoing to be using all the skills and everythingwe've learnt in the previous sessions aregoing to be adding them together and thenbuilding a simple calculator. So now whatwants to do is to have three inputs collectthree inputs from a user, which is the firstnumber, the second number on the operator.So the calculator want to do this very basicis just the one that is going to add, subtract,divide, multiply two numbers together. Sowant to collect a number, which would be numberone, and the second number, which would benumber two, and the operator, the operatoris whether you want to add or subtract, orwhatever you want to do. So now let's definethat to say no one should be equals to input.We can say enter first number. And then we'llalso do the same thing. I'll say num, twoinputs and second number. And then let's seeOpie, which is the operator inputs, and, operator.So now that we have the three inputs, whenI went to use an if statement, so what's goingto happen is if the op, which is your operator,is equal to addition. Now we just want tobasically add the first number and the secondnumber, then we're going to use an Elif toget his sub subtraction, whatever, then we'regoing to do, according to the operator, theusers input. So let's say if op is equalsto plus. Then is equals to close by just goingto print out number one plus number two Sonow let's just test that. So right here, letme say two, three. And I want to add nice,he says 23, which is very wrong, two plusthree is supposed to be five. Now the reasonwhy it says 23 is because he still sees thisas a string. If I over need to see it saysdrink, what is meant to see it as an integer.So because it's a string, he's just concatenatingit together, but we want it to be an integer,so it can perform the normal operation. Sowe have to say, ain't no ain't gonna pay stubbugs are gonna do the same thing for the secondone in a beast. Now, when we run these, itshould work. And our first number, let mesay 75. Our second one should be 25. I wantto add nice, it gives me 100. It adds it uptogether, that is what we want to happen.So let's just do some gestures. Or let's saythe addition is no one plus not two. But nowwant to check what if a user inputs subtraction,so if a user say subtract, then we just wantto print this subtraction is number one, minusnumber two, bow must make sure to disclosesigh right here was your no we can do thesewe can do the audition is no more close noto because this is a stream, this is a number.And then this is a string. So what we cando right now is to just put a comma, righthere, so we can just cover. So let's testit out. If I see 17 and 20, I'll just subtractit gives me the subtraction is 50, which isnice. And then let's do the same thing formultiplication. So we just say the multiplicationis number one, times number two. So that'sthe basic arithmetic for multiplication. Andthen we're also going to do exactly the samething for division. So if it's equals to divide,then we just print out the division is nomore one divided by num, two. So now thisshould work. Now when I run it, and I say6020, and I want to divide, you see, givesme the division is 3.0. What if I do somethinglike the absolutes of these? Oh, no. So absolutesof these, let me run it again. Now if I say60 and 20. I put divide. Okay, so you gaveme three points. You I was expecting you togive me three. But we're going to bypass that.So this is how to build a basic calculatorusing Python using getting user inputs andthen using if statement. If statement Elifstatement. So let's add one more thing. Soif the user doesn't input plus, minus times,or divide, what we want to just tell the userthat will be on iOS was in print, and canjust say, invalid, operator. So let's testthis out by running it. As a user says sisty.All 90 this time on seven, and you're gonnado something like dollar sign. It says invalidoperator. But now let's run it again and testfrom beginning. So let's test for the additionnighty 20. Paddy showed us me one 110. Nowlet's test for this subtraction. We are 50we have 70 So pratiques, it gives me minus20, which is the correct answer analysis forthe multiplication 40, we have four. And thenwe have multiplication. Now it says wantsto see, which is correct. And therefore thedivision also, we have 80, we have five, wehave division, sustain point zero, now everythingis working fine. So I hope you understoodwhat we did by building this basic calculator.In this tutorial, we're going to be talkingabout try accept in Python. So what this doesis that it prevents an error. So most of thetimes we are working in Python, you're gonnaget a lot of errors, you might do some thingson the program is going to draw an arrow oran exception. So most of the times this errorjust stops, our programmers cut our program,if our program is running during a specifictask, once an arrow comes up, do program isdown. So to prevent this, we use the try acceptmethod. Now this is going to get automaticallyget an arrow, and then just print whateverwe want to tell the user. Now for example,you know, when we want to do an addition,we want the user to input an integer. Butlet's say the user inputs a boolean valueor string or something else. So instead ofthe, but you know, Python telling train anassertion or train has an error, we can automaticallytell the user that invalid input that thisis not a string or something like that. Solet me show you how to do that in Python.So now, let's say I have x is equals to inputsmfsa integer to be specific input, they willsay, input an integer. And then we print x.Now when I run this was the inputs are integer,it print x, it prints seven, the interior.Now let me run it again, and input a string.Now you see that it gives me an arrow namedvalue arrow, in Valley literal for int. Soit's saying h J, K is not an integer. So wecan just automatically get this arrow by ourself,and then, you know, tell the user insteadof Python, train this exception, which canstop our program. So for us to do these wantsto do, we're going to say, try, like this,that oh, this is gonna be in try it afterit, we're going to say, except, don't, we'rejust going to print value, not an integer.So this dry is saying, try all this code,then if there is any exception at all, justprint value, no an integer, or we can justprint something with drunk because we don'tknow what's my cost. The exception is mightnot be that user inputted a string, it mightbe something else. So there's just say somethingwent wrong. Please try again. So now whenI run these, and I input theme, now you seeit says something went wrong, please try again,it didn't roll this error, like the last time,so does how to basically use try except inPython, but it's more deep dandies, we canget, we can use the exit method for some specifictype of exceptions. If I scroll up here, you'regonna see that this exception it gave us iscalled value error. Now we can say, exceptthere is a value error, then say this. Thisone I'm doing right here is just guessingif there is any error at all, but let's bespecific. Let's see if there is a value error.So now, if there is a value arrow, a valueerror means the user inputted what we don'twant to ask for a string and then input somethingelse. There was say there now we cannot sayvalue. Not a string, but not an integer. Nowwhen I run these Scroll down to somethingelse. Now it says value not an integer. Whatis it getting for only this type of error?Now let me try to add another arrow intentionally.So let me say, let me try to call cat needswith a name. So right here, I'm trying toconcatenate with a variable named name. Butwe didn't have any variable like that before.So it's going to give me a name error. Sowhen I run these, I would rank. Now you see,like, if you scroll up, the shows me namearrow name is not defined. So what if I justput only accept and I run shows me name isnot defined. So this is because we're tryingto define something that is not like a variablethat is not the so that arrow is from us,which you can pass something like this. Butnow we're trying to pass an arrow from theuser, we're trying to make sure that the userdoesn't input anything wrong. So now we sayexcept value is not an integer. So I hopeyou get the basic concept of try accept methodin Python. Now it also do something like thischanges, but something went wrong. Becausesee, something went wrong. Now, when we saysomething went wrong, after this, we can sayelse. Print, nothing went wrong. Now whatthis else is doing is that after typing afterrunning this code, if there's anything thatwent wrong, you should do this. But if everythingwent fine, then you should say nothing wentwrong. Now let's run this is asked me foran integer, I want an integer. Now it printsout the integer and he says nothing went wrong.But if I run it, again, inputs A strange noise,it says something went wrong, but he didn'tsay this. So this else is, if everything issuccessful, if there is no error, then he'sgonna say something, nothing went wrong. Thenthe last one I'm going to show you is calledFinally, is also a key word. Now this is goingto run either there is an error or not. SoI can just say, try accept, finished. So whetherthere is an error or not, this is going toprint f seven, there is no arrow, it's printseven and says try is finished. If I run itagain, and I print a string, so it says somethingwent wrong, which is these and it says tryaccept finish. So that's just saying thatafter everything if there's a problem or notjust print that try except finished. Now Iwant to talk about reading files in Python.So sometimes when coding with Python, youmight want to work with some external files,let's say like a text document, or like, likea spreadsheet, like an Excel spreadsheet,or like an HTML file or any external file.So he wants to know how to read and writethat file. So let's put that to practice.First of all, let's create a new file righthere. And let's just name it something likeit's been saved these and then I'm just gonnasave it in the same place. I saved these.So let me see all files. DSR, I'm sure islocated here. First of all, let's cancel thisand make sure we know where this is saved.Yeah, if I come here, yes. So I see whereit is saved. Project john. Good to right.Yeah. So now I can create a new file and thensave it. So right here, I can save it as somethinglike countries. t x t. See, it's ready onthe txt, I can just change it to all files.So in this countries, I want to have justa list of random countries. So I can say Ghana.I can say Mexico. I can say Morocco. Let mesay Spain. I don't have any spelling errorsthere. So Ghana, Mexico, Spain. Yeah. Thinkas Okay, give me one more see France. So Ithink that's okay. So now for us to read thisfile, we have to like import it into thisour Python file. So it's very easy to do,what we just need to do is to say open countries,which is the file name dot txt. Now, we needto make sure that these countries are txtis in the same folder as this Abdo pure sowe can easily navigate to it. And then aftersaying this, the second parameter This isgoing to take is R. Now what these are meansis we want to read on this file. So once we'reonly read this file, we don't want to editanything on it. Then there's also somethinglike W. Not w means want to write on thisfile, we want to edit this file. And we alsohave our plus a, this a means what to appendto the file, so we can add in the middle ofthe file or modify the file or make any changes,we just want to append to the ending of thefile. And then we have one more call our plus,this means we want to do both reading andwriting. So give us full capability. So that'swhat the outflows is for. But for this part,we're going to be working only with our sowe're opening this file. And most of the times,we always want to save it in a variable. Solet's just name a variable file, country file.And then it should be equals to this. So ifwe print and anytime that we open a very file,and then we open a file, we'll resolve tomake sure that we close the file. So downhere, we can also say, country file, dot close.So this is to make sure that our closing thefile. And then in between those, we can doanything you want with a file. So now I canjust simply print golf file. So first of all,I want to check if this file is readable ifI have access to read it. So I'm just goingto do is to say cow file dot readable. Nowthis is just going to return a boolean valuetrue or false. So let me run this. So nowit says no such file in directory, countriesdot txt. So let's make sure. So what we'regoing to do is to navigate into this folder,and make sure we create that. So let's gothere. I think I have it in right here. Sothis is in project. Okay. And then Django.So I think I'll be right here. And then thereis countries dot txt, c o u n t ri is CE ou n t ri ES. So it says that we can't openso it says no such file or directory. So whatwe just need to do is to do something likethis. These, although this is not the reasonwhy we're having this error. So when we runthis thing gives us that error. So the bestthing to do is to just take the main directoryto dads and then paste it needs this slashlike this. So now let's try to run it again.Now you see it says it gives us this error.Now the reason for this error is this slashright here, so we're just going to changeit to slash the forward slash right here alsoAnd then when we run it again, now you seeit says true. So the reason we add the arrowis because right here is always in a backwardslash, but we are using in Python, it hasto be in a forward slash. So now we are successfullynavigating to dat countries dot txt. So whenwe say, print confer the redo, so we're askingis, do we have access to read this file, itsays true. So we don't have access, we canread it is going to tell us false or not thatthis is true, then I think we are good togo. So now that we can read this file, whatwe just want to do is to bring something likewe can see curl file dot read line. Now whenI say this red line is going to print thefirst line of this file, which is Ghana. Soonce I print these, you see now that it'sprinting Ghana, and this is like a sequence.So if I print this file, again, if I say print,and I see a cow file dot read line again,now what is it going to bring the second line,and knows that I didn't make any change thesame code, but when I run it, it prints Ghana,unmusical, secondary, do this and just print,everything I have in the body most recommendedway is to just say, Gulf print lines, nowbrings lines is going to print everythingfor you in a list, so it's going to printeverything out, do lines of your vendor file,and then store it in a list. And now we canjust get let's say the first one, I say wantsto get the first one. Now we are willing Ghanagang kids. Last one. Now you see we are France.So that's how to use the realize function.And then we can also making more cool by loopingthrough this. So we can see for, again, changesto a for loop for fells in curve dot readlines, like this, then we want to print wejust basically want to print files. So now,when I run it, you see just basically printall the old lines in which I have. So thebest way to call this is lines not Hell'sso lines. So when I run it again, same thing,it just print all the lines if I was a commieand make some change, like say Ghana is acountry a free on the nice CV. As I run it,that changes automatically made by move up.You see right here, the first line says Ghanais a country in Africa. So I'll be gettingthe concept of reading files in Python. Theseare you can read files read by lines, reallyby text and stuff like that. Now let's movestraight to the next part of this tutorial.In this part, we're going to be talking aboutwriting files in Python. So in the last part,we talked about opening or reading by readingfiles, reading external files in Python, butin this part, we're going to be talking aboutappending. This is some text to the file,or those writing the old file again. So first,to write a file, right here, we need to changethis R to W. So now when we change this outto W, let's just remove these as then we canjust say golf dots, right. And then what youwant to do is to just write the ofa. Now youcan see that this is the file, but if I inputsomething, you know, like, this is the newtext. Now when I run this, you'll see thatnothing happens with that coming year, yousee that it has been changed. Everything Iwas there was gone. So we wrote the wholefile again. Now this might be useful. Let'ssay you want to write a new file. It's veryuseful. So the The reason why it ruins everything,again was because it was an existing file.So it overrode like a router need. But thisis mainly used for creating a new file. Solet's say we want to have country now. Nowlet me say, this is the new country. Now onceI save it, and run, if I call into this directoryright here in my command. So I'm going todo C, D, enter the directory. Okay, itdoesn't go to that directory. But what thisdoes is that it's created. It's great thisnew file called country dot txt in that directory,so let's go there normally. So right here,you see that we have a new file called country,let's change it and just say new file. Nowwhen I run it, let's remove this space. WhenI run it, you see nothing happens, we're righthere, new file is created. Now, that was allto create a new file and automatically writesomething inside it. So let's just Ctrl Zback to the countries we were using. So now,I have this country's file, let's say I wantto append something to the bottom like a newtext, what I can just do is something like,well, to append, I must make sure I changesw two a. And then right here, what I'm justgonna do is you just say, file dot right,then this is a new line. Now when I run theseknots in opposing determinar, or when I comehere is a pen, this is a new line to eat.But you can see it joins it together. Nowlet's see how to form a new line I want thisto be aligned to I can just come here. AndI can see backslash n. Now these are magicallygoing to take you to a new line, when I runit, again, are kamiah, you should now knowthat this is on a new line. So that is basicallyhow to append in Python. Now you can do thisfor various types of videos file extension.As you know, we did this for the text document,which is dot txt, you can even use a Pythonfile to open a new Python file. Now let'sput that in action. Now let's say want toopen a new file and name it new dot p y. Andthen in that new dot p y i want to write andthey weren't allowed to write in it. So righthere Now, let me just crude, these, I canjust easily write a Python code, I can sayprint. This is a new file. So right here,I just wrote a simple Python code. And thenobviously, we have to use the backslash beforewe can write a code. So right here, I usethis print, this is a new file, and it's gonnabe in this new dots pure. So now when I runthese, you'll see now that we have a new.pyfile. And then I can just when I come here,I can run new dot p y, you see now that itjust simply prints out this is a new file,which was the command or the line we put inyet. So it is also very important and veryuseful writing the new files in Python. Nowwe're going to be talking about classes andobjects in Python. So I must say that Pythonis an object oriented programming language.So this means that anything that deals withclasses, objects, and things like that, wereclassified as object oriented. So classesis just like a feature in Python, say somethinglike a function. A function is a feature thatPython as their classes is also a featurethat Python book classes now is like a constructorof objects. So you might not understand whatI'm saying now, but when I show you the code,I'm sure you get it more easily. So a classis like a construct of different objects onthe class, we have various objects. So let'sjust go ahead and show how to do a class.So now I want to go to class, we're just goingto say class using the class keyword, thenwe can say, my class. Or then on the year,we can see x equals to five. Now we have thisclass. This is the class, the name of theclass is my class. And then we have a x, whichis an object on that this my class on x equalsto five. Now want to create an object, thisis actually a value, or I can say an attributeon the class. Now, let's say we want to createan object using this class, we're just goingto do is to do something like p one, somethinglike that. It goes to my class. Though weinitialize it, there will gossip print beone dot x. Now this is going to print five,because we're saying that P one is equalsto my class, which is this class, then we'lljust say print p one dot x, once I run this,it brings five. So that's how to basicallyprint dude that now let's talk about the initfunction. the oddest thing I just said, Now,those are the basic concepts of class wherewe can basically use them in real life lessonyou reward things and reward projects. Butthe init function allows us to initializedifferent values in our class. Now, for example,we have this class, let's say this class isnamed person. And then on the other class,we're gonna have a function. Gonna take twounderscores in it like that, then you're gonnahave some parameters self. Now this stuffis gonna be there is just there. That's theway it is. And then let's say it does name,which we are going to put our, let's say,as age. And then. So we put our colon justlike a normal function. So let's remove these.And then to determine the name of this self,dot name, can be equals to name. And therewe go, oh my god. And then we're gonna dothe same thing for the age. So that age isequals to age, just like that. And then let'sjust initialize it the way we did here. SoP one equals to my equals to person this timearound. But now we have to give it this name,and this age. So we'll say the name, we cansay the name is john. And then the age is87. Now once we print p, one does name. You'llsee that it gives us, john. Okay, so now itsays indentation error. So this is under thisfunction supposed to be indented. So let'srun that again. Now you see that it's printedjohn, we can also print B one dot h. And theywant to see that it prints at seven. Now alsomake this allow user to input. So we can sayname is equals to input alkazi, enter yourname. And then we can say age is equals toinput a, which you can say, and your age.And then once we have the name and age ofthe user stored, we can just replace it withthese as a name. I say Ah, now when we runthese, first of all, it asks us for a name,but I said team, it's the NIH, NIH just printsteam at night. So we can also use a classto do something like that. So classes arevery broad in Python, and it is very, veryused in Python. But there are still some otherobjects properties that we can do that let'ssay we want to delete a property from theseicons or delete this age. So let's just removethese and then let's give it the 10 Join.Now, let's say wants to delete his age fromit, what we can just do is to just say, dlp one dot h. Now, once we delete p one dotage, this is not going to have this age init again. And then we can just even deletethese objects in total by just saying deletep one, once we run this, this is gonna bedeleted. If we try to print p one after that,it won't work. Now, he says, Your name notdefined that because we've already deletedp one, there is nothing like that. So we canprint what is not. And then we also have onefeature we can use in the class. So righthere, let's say we have a class that is namedperson. And for now, we don't know what toput there. We don't know the values, and wejust want to continue coding. Okay, so toencode pass, so this pass allows us to bypassany error. So if we have like, this classthat is empty, we can just put pass for nowthey come back, like add attribute. So itwas I put pass, and I run, this could notinnopolis. But if I just only put class personand I run you see is gonna give me an arrow.So this passage just to bypass the arrow,so we can continue with our code for the main.Wow. So I hope you get the concept of classand objects in Python. Now we're gonna betalking about inheritance in Python. So Naritasimply means taking from an existing class,and then getting all the metals and everythingin there and putting it in a new class. Soyou're gonna understand what I mean in a bit.So let's say we have an existing class inthis file name new dot p y, I just createdthis file we actually created earlier in thisvideo, let's have a class name, student. Andthen let's say that name is equals to sameage is equals to 34. And LSA gender is equalsto mu. Now we have this class here, we caneasily import it by saying count can see fromnew.py import student, which is this righthere. So now we are importing student. Soinstead of saying from noodle spy, we canjust say from New without adding p y, theextension, it automatically gets that we areimporting from this file. But before we gotimpulse, we need to make sure that this newup I in the same directory. So let me justcancel this, we need to make sure the samedirectory. So now I have this new class namedperson, what I just want to do is to justsee this student. So I'm getting everythingfrom this to dance class, which we narrated,I'm just putting in this space in clubs. SoI just put pass to avoid any error. Now Ican say p one is equals to person. And I cannow say p one dot name, I can just said print.b1 does name. Now once I run this, you seeit prints theme, all the way from New Wi Fi.bunchgrass is running up.pi. So that is thebasic concept of inheritance in Python. Itinherits every single thing which we havein this class. And it does bring gates rightin this class. So it's like a duplicate ofthat class was not a duplicate because differentnames in different file. So it's called inheritancein Python. In this tutorial, I'm going tobe talking to you about the Python interpreteror the Python shell. So the Python shell isan application that is automatically installedwhenever you install Python on your computer.So let me just quickly open up my python shell.So this is my python shell right here. Asyou can see, Id issue So let me show you howI opened this up, you can just come here andjust search for ID l II. If you have Pythoninstalled issue automatically bring that outand just eat open. But since I already havethis open, so the Python shell is just likea smaller environment where I can run on quicklytest some Python code. Like everything we'velearnt in this tutorial, I can easily codethem yeah, like, let me say, print you enjoyingthis tutorial. Once I press enter, you seeit prints that immediately, it automaticallyruns that code. As I press Enter. And we canalso says like a very, we're gonna say nameis equals to theme. And then we can now printname. variety in the Python interpreter, wecan also print the name without even writingprint. If you just say name, it automaticallyprints it out. Well, that's only when you'rejust testing your code yet in your Pythonshell, you can do that in your main editor.Now we can do a lot of things like I'm surewe can use a for loop. Let me say for letterin same Yeah, like that. Then I can just seeprint later. Now you see it's automaticallyprints team, I can do anything in year I caneven write a class. And I can see the classin the person. And then I can see name isequals to john. And then right here I cansay p one is equals to person. And then Ican say p one dot name. This is just gonnaprint me john. I can basically do everythingI do in the code editor right here. I canhave an if statement. Let me say if b wondersname is equals to john, then print Yes, itis. So now he's gonna print Yes, it is becausepianos name is obviously equals to john. Andthen we also perform our basic arithmetic,like two plus three gives us five, nine minuszero gives us nine. And everything which wecan do on the normal place. Because we'lldefine a function, let's say we have a functionto say, I and then let it pass a name. I letthe name be unnamed. Under let's say print.I name now let's see I give it john. Now yousee it says I joined. So almost everythingwhich we can do in year, we can also do itin our main editor is this like the same thingbut is not advisable to use these when buildingnormal projects or stuff like that. This isjust basically for testing or anything likethat. So let's also try more things like tryaccept. So try, let's say age should be equalsto any of the inputs of enter age under thisglues that so I wanted us to be age and thenwe just say exit Yeah, we must make sure wehave the right indentation. So except it givesus an error because of the interpretation.But we can basically do all these writingin our Python ideally is what I want to showyou. So sometimes you might run into thiserror of indentation syntax. Because is theindentation is not really obviously clear.Just like the way it is right here in VisualStudio code. So that's why it's recommendedto use your normal editor and not basicallyan ideally for editing, but often get theconcept of a Python shell. That's going togo above the Python interpreter. So now we'regoing to be creating a simple signup and loginsystem in Python. So we're going to be puttingin everything we've learned in this tutorial,and then building this simple program. Soas you can see here, it says, create youraccount. Now it says the input username, I'mjust going to input admin, and it says weshould input password. I'm going to inputadmin. As the password now says user admincreated successfully login now. So what thisprogram does is that it creates this user,obviously one or Jenny, we read database,we're just storing this in variable. Oncewe run this program, again, we have to createagain. So it's just four practices. So oncewe create an account, and he says use ourgreatest This is really, it says login now.Now when we try to log in, if what we typeis the same with these, then automaticallywill be logged in what is different if ourusername is wrong or password is wrong, thenyou just say invalid credentials. Now letme try to log in with normal. And I say adminnow says user logged in successfully. Letme run this again. Let me let me now createanother one admin, again, admin. Now it saysadmin created and wants me to login. If Inow say admin, by the password, and I addto n, I click enter. You see now it says invalidcredentials. So this Python program we'regoing to build is gonna get whether the passwordis right, or the username is right or not.So let's go straight into that. So let's justquit these come back here. We can also quitthis. So what's one to do? We're going totake in four parameters. So the first oneis going to be the user name and the passwordfor creating accounts. And the second andthe third, and fourth is going to be username and password for login. So let's do that.Let's say user name will be equals to so thisis the first is our new for creating account.Because to our inputs, I will say and username. And then for the password, say the samething inputs into a password. And there wasusers enter the username and password, wecan just print to the user and simply saythat your account has been created successfully.And then now we know how to tell the userto login. So let's print again, login now.So now once you have another variable, whichwe use our name to, should be close to inputand user name. And then the password for thelogin. password to input and password. Sonow we know the Jq DS is equals to this. Sojust simply say if user name is equals touser name two, and password is equal to passwordtwo. So this is our if statement saying thisand these must be equivalent. That's why weuse and if we use all is going to be wrong,because if the user name is correct, and thepassword is wrong, it's still going to lookto us I so want to make sure the two are correct.It took correct response before we log in.So once it's correct, we can just say printlogged in successfully. But it was wrong else.We just want to print invalid credentialslike this. So let's just come on to the tophere and print something like that. Createaccounts now now this should work let's runit was just so we create a user name let'sjust say to me the password see me now youraccount has been created successfully login now see me on the password see me now itsays login successfully. Let's run it againand try a wrong one others hai hai hai, haihai hai. Now when I say the user news, ah,ah, ah, ah, ah y. But the puzzle is Ui UiUi. Now, you see, it says invalid credentials.So that's how to build that basic Python programusing getting user input. And if statement.I hope you understood what we did here, ifyou did it, you cannot go back in like fiveminutes ago, and just watch from there, I'msure you're going to get it. In this tutorial,we're going to be talking about modules inPython. So modules basically allows you toget the function class or everything presentin another file, it allows you to implementit and use those same functions in your ownfile or project. So modules is very, veryversatile is very widely used in Python. Everybodyuse modules. So let's say I have this filenamed noodles py. Now, I have a function namedsay I. And then that say, I function, I justwanted to print. I know, Bob is functioninghere, I can import these, I'll just say importsnew. Now this new is starting as a modulefor this my file. Now right here, I can justsimply say, new, don't say I was I CDs, Irun this file, you see that it automaticallysays, so does how to use modules in Python.Now there are a lot of things we can do withmodules. And modules are very versatile. Soif you want to, like I wanted to use a functionthat says, instead of coding from scratch,there's possibility that someone out therealready written that same function, or similarto what you want to do. And rarely as he doesa module or library, in mutual gain, get andimplement. So now modules are in just on yourlocal laptop or your local PC like this, modulesare hosted online. So Python as somethingwe call Pip, which I'm going to talk moreabout in the next video, the next part. Soall the modules are more hosted online. Let'ssay you're looking for a module that wantsyou to just do a specific task. And you knowthat yes, of course, someone else would havedone this, then you can just go and searchfor that module, or search around researchthere, you're gonna see that module online.In the next part, I'm going to show you howto implement peep and then install all thosekind of modules on your computer. So in thispart, I'm going to be introducing you to somethingwill go beep. Now P is used for installingexternal modules from the web to your localPC. Now, as I explained in the last videowas modules, they basically allow you to getus function from another file of Amanda library.So PIP allows you to install a module fromthe internet to your laptop. Now, if we goonline, and then we just search for somethinglike Python modules, then we can just see,let's see. Let's go to P ypi. So there's asite called pure ipi. Now, this is where allthe Python modules almost all the Python modulesare being boosted. As you can see 200 andH 2000 project. So he just basically saying200,000 libraries or modules that are hostedon this site. Now you can see that each onehas different tasks they do. Now see thismodule is for Spotify recommendation. Let'ssay ah, let's say we want a module like, let'sjust go to the home page. And let's see whatwe want. So you can also see trending products.As training modules, a lot of different things.And then let's say, we want to let's go tobrowse development of framework. Let's justclick on this. So now this is the name ofa module. Let me look for Swan the as a description.So Django deep serializer. Django is actuallya web framework, which allows you to buildwebsites using Python. So this one is sayinga Django deep serializer. So that's what thisparticular module does. So while doing studieson our computer, we just type pip installDjango, deep serializer. The way it is beingsaid here, then how do we now where do werun this command, if you're on a Mac, justopen your terminal, move your new windows,open your command prompt, and the Angelusbasically the pip install Django, I thinkdeep ip serializer. Now, if this is the libraryor module you want to use, you can just runthis command line, and then it's good to goI installed this module or this library onyour local computer. Now you can see it saysdown collecting Django, deep serializer, thendownloading Django deep serializer 0.1. Pointthree and all those. So it's setting up allthese. Yeah, so you see it says successfullyinstalled Django deep serializer. Now I havethis on my computer. Now very sure that ifI want to import this, I'm just gonna lookfor our say we got imported. Those guys good.Okay, they didn't mention that here becausewe are not running a Django project. So youdon't need to understand what I'm saying fornow about Django. But this is how to basicallyinstall a module or library using PIP on yourcomputer that does what PIP is basically aboutthe and this beep. You don't need to listendownload peep externally, once you installPython be automatically installs with it.That's why Well, once you install your Pythonis good. If they ask if you want to installour component is good holistic, yes. And theyjust add Python to Python just tick everything.So the oldest components will be installedwhen you want to use them later. So PIP isautomatically installed with Python. So ifI come here, we just say for Pip. You see,he says, Let me say Python, let me be specific.So PIP Python, is a package management systemwritten in Python used to install and managesoftware packages. So as I said, Pip is usedfor downloading, or in this case, installingpackages. So modules are Swick also calledm packages. So P is the manager is what downloadsit and store it on your laptop or your computer.So does the basic concept you need to crashabout peep. So guys, that's gonna be all forthis tutorial. I hope you learned somethingand enjoyed the video. Welcome to the DjangoCrash Course. The main purpose of this videois to introduce you to Django and show youall the concepts you need to start buildingyour own project using Django. In this tutorial,we're not going to be building any full projectbow we're going to be doing is taking eachDjango concept step by step using it in apractical use case. And then by the end ofthis video, you will know how to build yourown projects using Django. Now, this tutorialis mainly focused for beginners, because we'regoing to be starting from the basics to themore complex stuff in Django. So a quick introductionto Django. Django is a Python web framework.This means that using Python, we can buildweb applications with Django. So without wastingany time, let's get straight into this videois a list of what we're going to be coveringin this video. So let's get straight intointroduction and installation of Django. Now,the first thing we need to do is to installand set Django up on our computer. So I'mon a Windows as if you're on a Mac or you'reon a Linux, the installation process is quitesimilar, just only some differences in thecommand line. But I'm also going to see whatyou need to do if you're on a different OSfrom mine. So this is just the job Go officialsite. But now before you need to install Djangobefore you can install Django, you need tohave Python installed on your computer, becausewe're going to be using a Python package managercalled Pip. And that only comes when you havePython installed. And Django is a Python framework,so why not. So if you don't have Python installed,just go to Google. And then it's very easy,you can just search Python download, and thenjust click on the first website. Yeah, soyou're gonna see the latest version, yeah,and you can just easily click on this to downloadit. Now when you download it, you're justgonna install it like a normal application.So I'm not going to do that, because I havethat installed already on my own laptop. Soif you don't have this installed, just comehere, download this, and then everything isgoing to be fine. So now we can quit thistab. So now we have Python installed on ourcomputer. What we just need to do next isto open up our command prompt. Now these arecommand prompt zero are going to be doingmost of the server running the installationsand everything we need to do in our Djangoproject. So the first thing we want to dois to install Django, it's very easy, whatwe just need to type is pip install Django.Now this command line is going to installDjango on our computer, so it's going to installDjango on the system, so we can access itfrom anywhere. But I have Django installedalready. So what is going to tell me is requirementalready satisfied. If you work with Pythonvery well, you know that once you have Pythonmodule, or library or package installed isgoing to tell you requirement already satisfied.So as you can see, it says requirement alreadysatisfied. So I'm gonna do I'm just gonnaclose these, and then just keep it like that.Now, you can see that we have Django installedon our computer. And the version that is goingto install is the latest version. Now I'mnot really sure if it's 3.2 or 3.1. I knowthat won't Django three or so right now. Andthat is what is going to install the latestversion. But let's say for a different projectfor each Django project, you want to havesome particular packages just for only thatproject not for on your entire computer. Ialso have a different Django version justfor a specific reason on each project. Nowwhat we need to do is to create a virtualenvironments, virtual environment, I willsee it's like a little box where everythingyour project is stored in. So it's just likea mini environment where you can assess everythingabout your project. So the Django versionof that particular break is different, thewhatever version you are using for any ofthat package installing can be different.So it's just for that particular project isnot going to be available in the old computer.So for it to do that you need to first ofall install a virtual environment on yourcomputer. Now the counselors my driver mateyou can have, the one I use that I recommendis called Anaconda. But that also has hisinstallation process. And that is mostly usingAnaconda using machine learning because ofthe packages that comes with it. But for thisproject, we're just gonna stick with a verysimple virtual environment. And this virtualenvironment is very easy. We are just goingto install it on our command line right here.But it was Anaconda you have to download theapplication, just like we did for Python andthen install. So if you want to check thatout, there are countless tutorial series onYouTube about it, you can check it out. Butlet's just install a virtual environment righthere on our command line interface. And thisvirtual vironment is called Virtual env wrapper.So to install it, we'll say beef install Virtuaenvy, rubber, and then after doing this puton iPhone, and then we'll say when and thiscommand line is going to install it on ourcomputer. So again, I have this installed,so he's going to tell me requirement alreadysatisfied, but for you, it should say shouldgo ahead and install it. So I'll just sayshow the loading bar downloading or somethinglike that. Now note that if you're on a Mac,when you are installing all these packages,you need to type PIP three. So you can seethat right here on the windows we type pipinstall, then we type the package name, butif you're on a Mac, you will type p3 installThen the package name. So that's just themain difference within the windows and theMac installation. So now that we have thesevirtual environment rapa installed, let'snow go ahead and create a virtual environmentin Java Django project. So first to do this,we're going to say MK, which is short formof MC, then virtual envy. So now when we sayMK virtual MV, we're gonna leave a space,and then we'll put the name of the virtualenvironment. So you can give it any name,let's say you are working with a project namedonline dictionary, that's your Django project,you can also give the virtual environmentname as online dictionary. So just so thatyou can easily access it whenever you want.You can give it any name you like. But I justpersonally love giving it the name of my project.But now, they just give it a name of my app.So MK MV might help them get it Enter. Now,this is gonna create a virtual environmentnamed my app. And then once it's done creatingthat particular virtual environment, whatis going to do is automatically going to activatethat environment. So this will take a fewseconds. As you can see, we have this installedalready. And then before we installed it,besides the directory of where we are, wedidn't see anything yet. But after now youcan see we have my app. So this is showingyou that it does is it has created the virtualenvironment called my hub, and it activatedit. So as I say, you remember I said thatwe were using a virtual environment, it islike a different box from the old computer.But before we can assess that box before ourselves,our small environment, we need to activateit. So now that we've activated this virtualenvironment, we can, anything we are doingin this particular command line is going tobe in Dev and drive vironment. So now, I'mgoing to install Django, I when I installDjango by saying Pip, install Django knowsthat if you're on a Mac, you should be freeinstall Django. So now when I install Djangoand hit enter, is not going to tell me requirementalready satisfied again. And by now you shouldknow the reason why that's because we haveDjango installed on our computer. But we don'thave it installed in this virtual environment,which is separate from what we have on ourcomputer. So as you can see, it is installingDjango again, which is let's see if we haveYeah, installing three points two points tothe latest version. So that is the differencebetween your virtual environment and yournormal computer environment or whatever youwant to call it. But as you can see righthere, we add this environment as we createdthe virtual environment, it automaticallyactivated. So for you to know, if you've actuallyif you are in a virtual environment, or ifthe environment is activated, you are goingto see these brackets and then the name ofthe environment in it before the directory.So you know, when you first open your terminalor command line, the first thing you're gonnasee is the directory where you are in a virtualenvironment, you will first see the name ofthe virtual environment in brackets, and thenthe directory that should show you that youare in Dev and driver match. What if we closethis command line, or we close this commandprompt and come back, you know, we aren'tgoing to see this my app again. So I willnow tap into that environment or we activateor enter the environment. So I'm also goingto talk about that in a few minutes. So fornow, you can see that we have Django installedin this environment. That's very good. Now,we're in a virtual environment for a whilelet's move straight to Django. We have Djangoinstalled. The next thing we want to do isto create a Django project because we wantto work with Django. Now Django has this commandline, which allows you to create a projecta new project. So first of all, you need tomake sure that you are in the directory youwant. Let me open my folder real quick. Sothis is my folder. This directory is whatis in this command line. So you can see righthere, project slash Django tutorial. By komiya.You see down in projects Django tutorial.So this command line is open is open in thisdirection. So anything I'm creating, I'm creatinga new Django project is going to be createdin this directory. Now, I'm just gonna sayDjango admin, start project. And then let'sgive it a name of my app. So yeah, my appis okay. My project. Let's just give him myproject. So you can see Now we are the virtualenvironment in my app. And then this is thecommand line that we're gonna use to createa new Django project. So once I hit Enter,and I'm just gonna give it a few seconds.So you can see, it didn't show anything here.But if I come back into this page, you seenow that I have a new project named my project.So let me come back real quick. We did wasDjango admin start project my project. Now,this is going to allow us to create a newproject Django admin start project, then thename of the project after so if you're workingon, let's say, an online search engine, oryou want to name it, getting search, automassage, or whatever you want to name it.So you can say Django admin start project,then online search engine, or whatever youwant to name your. So that is how to createa simple Django project. Now, if I press dir,I see that I have a new file, a new folderyet, let me opt into that folder, CD my projects.So now I'm in my project folder. If I pressdir again, you can see I have money that wason my projects, I'm going to explain all these,they may look confusing at first, I'm goingto explain all these I promise. So I'm justgoing to quickly explain how you can alsodo all these things in Mark. Now creatinga new project is exactly the same thing. Justlike Django, I think admin start project myproject exactly the same thing. And then righthere, when I press dir, what I did was tosee all the files on folders in this particulardirectory. So if you're on a Mac, what youneed to type is LS. Once you type l s, letme just quickly type it right here. This sothis if I click enter is not recognized becauseI'm on Windows but the only mark is goingto show you a list just like this of all thefiles and folders you have in that directory.And what I did was to go into that my projectfolder, exactly the same thing with Mark justtype cd, my project you're going to go in.So now we have this let's come back. Let mego into this project. What do we see herewe see a file Monday money.py. And then wesee a folder, which is given the name of ourproject, which is my project. Let me openit. And we see like, a bunch of files here.And I'm going to explain all of these. Butbefore I do that, let's bring this projectinto Visual Studio code. So now, we have talkedabout doing everything in the command lineinterface, creating the project. But whatdo we actually want to code. So we need ato an ID, a code editor, whatever you wantto call it. And the one I love using is VisualStudio code. So you might want to use autome my own is pi charm in my own or use warehouse,why Sublime Text, but I use Visual Studiocode, anyone you want to use is fine, as longas you know how to use it. So now I have VisualStudio code here. I'm just gonna say, Comehere, click on file. And then I'm going toopen up a new folder. I'm not Oh, yeah, I'mopening up a new folder. So she'd been projectDjango tutorial, my projects. So I want toopen this folder, select folder. should takea few seconds. Good. That's why I like VisualStudio code, because it's really quick andlightweight, compared to some other extentfrom other ID. So this should open right now.So give that a few seconds. And, yeah, soas that is opening them quickly say something.So it has opened right there. But let me justclose these. So remember that I said, Whatif one of us says this particular virtualenvironments, let's say we close this commandline interface, I want to assert this virtualenvironment. I'm going to show you how todo that in our Visual Studio code. So let'sjust come here. So first of all, this is thefiles we get when we create a new Django project.This money does py file, you don't want totouch it throughout your coding throughoutwhen you're building anything you're building.It is I personally, I there might be somedevelopers will manipulate this fiber. Normally,as a beginner, even as an intermediate Djangodeveloper, you don't want to touch this file,there's nothing you want to do here. Thisfile is just to allow us to do several thingsin our project, like run our project on thelocal host. So we can see what we are building,migrate databases, and I don't want to getinto details, because you might not understandnow, but you understand later. But for now,you don't want to touch this file. So let'sjust close that up. And then when we comeinto my project, we have an INI file. Yes,this file is empty. For now, there's not muchto explain in this file legislatively likethis. So what's it gonna use all these fileslater in this tutorial, so I'm just showingyou like a boilerplate that Django bringsup when we create a new file, so we're gonnause this as gi is an important one. It wedon't need much manipulation in this is justone line of code or something just to assesssome socket and stuff. So just leave thatfor now. And then this settings file is likethe bedrock of your whole project. So if youdo anything wrong in this settings file, it'sgoing to affect your project. So we need thisfile, we need this file a lot. We're gonnause it to like this installed apps, we'regoing to do some things in this, we scrolldown to see where we have templates. Thisis empty. For now we're gonna do some things.And then we keep going, Yeah, we're gonnado a lot of things in this settings file isjust the file that has all the everythingwe need in our project. So all the configurations,and the apps when installing anything in allour data bases is inside this file, we'regonna configure it. So now we have this URLsdot p y file. Now let me explain what is yourspy file does this weird up to y file, whatit does is what we're going to come in here.And then we're going to specify all the URLswe want in our project. So for example, let'ssay we have a website named www dot COVIDtomi.ml. Now we have that website, when auser just comes to code return mi.ml. Whatpage do we want to open is you are going tospecify it, but whatever user goes into COVIDtomi.ml slash newsletter, or slash blog postor something. Now slash is another web page.Another URL is here. We're gonna specify itthis year, we're gonna configure each URLwe have in our project to us. We're gonnago talk about that later in this course. Andthen these Ws gi, yeah is kind of similarto the SGI. But for now we're gonna leavethis. So right, we have all these. Now, whatI want to do, I actually love working in thiscommand prompt. But what I want to do now,first of all, I want to deactivate this virtualenvironment. So it's very easy. All I justneed to do is type D, arc safe v. Now youcan see we're not in the virtual environmentagain. But now I'm away from Java travelmate,how can I assess it back? Let's go into VScode. In VS code, we can have our terminalour small terminal right here. So we don'tneed to jump back to command prompt everytime we need to do something. So right here,you'll see that we have this terminal, itwas going to give it a few seconds to loadup. That shouldn't take too long. So righthere in this terminal, we're going to Yes,this is a we're going to assess our projectis ready in this project directory. Now let'ssay we want to go into the virtual environmentvery, very easy. We just need to do say walkon a shame of this. And then we'll say thename of the virtual environment in Mr. VijayVerma was my No. Normally, we should havesomething like this right here, what is notyours? Let's come into our Vish command promptand say work on my app. So right here, youcan see that it brings out the virtual environmentback that showing that we are in this virtualenvironment. So in VS code, it is supposedto do the same thing, but I'm sure that isbecause it's using maybe another type of commandline interface or something else. But yeah,that's gonna be a minor problem. We can justoverlook that. But this is how we can deactivatefrom a virtual environment and go back intothe virtual environment is very easy. So letme just quit this. Now, what we did was, wecreated a new Django project, we installedDjango, we talked about virtual environment,I explained all the files for this files,which was created when we created a Djangoproject, I explained the command line interface,we've done a lot to introduce Django. So nowI'm sure it should at least have a gracefuljust understand what Django is about. Andnow we can start working with it. So now thatwe have our Django project created, what Iwant to talk about is the Django app. Now,this might sound funny, but there is a differencebetween your Django project and your Djangoapp. I'm going to explain it using a popularsite. Now the Django apps are like subsetsof the main project, we have this projectcreated right here. Inside this project, wecan have multiple Django apps, so they'relike subsets of a particular app. But whywould we use a Django app one, we just alreadyhave a project here. Let me use for example,like Instagram has come to explain. So wehave Instagram. In Instagram, you know thatwe have different sections, we have the feedthe photo feed, we have the marketplace, wehave the direct messages, we have the storyand plenty of other things. So Instagram mightbe the main project, just if we're using DjangoFor this example, let's say Instagram is themain project, then we have the direct messages,that can be a particular app, another appjust for only that direct message, we canhave another app for the marketplace, we canhave another app for the reuse, we can haveanother for your stories, we can have anotherapp just for the photo feed. Now, each appcan just have a particular function is doing.Now, in plain most projects, you don't havetoo much apps, you might just have one projecton one app with the project, I've been doingthat as well. But if you like have a verybig project that you want to do that willrequire plenty apps, there is no problem doingthat. So that's what apps are in Django, theythe main project, and they are the subsetsof that project, which are apps for differentfeatures. You can also have one up your oneproject or one up and you can just have multiplefeatures. That is also totally fine. It dependson how you just want to arrange your project.But one project I want at least I will createa Django app very easy, just like we createdthe Django project. First of all, we needto make sure that we are in the environment.And then there we are in the directory ofour project, the root directory. Now whenI say root directory, what I mean is the directorywhich goes contains the money.py file. Thatis the root directory of this Django project.So we can confirm the wind is the root directoryby saying Dir. So we see money.py. This tellsus that yet you're in the root directory.Now to create an app does when we use thismanage dot p y, in earlier I explained thatthis money does pure y, we don't really wantto code anything inside it, but we use thefile a lot for different things. Now, creatingan app is one of the times we use that money.pyfile, we'll just say python manage.py. Startup. And then we can name this my app, sinceI do have my project name in my app. And thenwhen we hit enter, is not going to give usa response right here on the command lineinterface. But if we go into our Visual Studiocode, by Come here, you see now that I havea new folder named my hub. And under the Ihave a new, another folder and a bunch offiles. So let me just quickly go around andexplain if so this in it, we really don'tdo much inside. This is just for the migrationsfor the models, I don't understand that later.This admin.py Django has this beautiful admininterface, which allows you to control yoursize or maintain your size you view or thedatabase is everything you need to know aboutyour site. And this admin spy file is wherewe register some database you want to putin there, and some other things we want todo. And then this ABS Wi Fi, we also use itbut not too much. But let's just keep that.And then these modules are py file is thefile where we create all our database. Nowdealing with database in Django is quite different.Because we don't need to write a single lineof SQL code. I'm also going to explain thatlater in this course. And that's what themodel is a PDF file is for the tests, we weuse it in some cases, but not four times,so it's not frequently used. And these viewsare pure is where all the main thing, Apple.So what we're going to look at this video,if you want in this video, is where we'regonna start from. So now, let me just quitthese. Now, f of these. Now, let's say wewant to start with the URLs configuration.Now the URLs configuration when I say thatwhat I mean, as I explained earlier, I saidis let's say you have a project, and theneach each link, let's say you have a websitelike youtube.com, then each particular linkis a different URL. So that's what the URLsconfiguration is about, you're going to understandthat in a bit. So what we just want to donow is to configure URLs, let me just makethis more understandable. So we have thisDjango project.com website. If I click onoverview, or I click on downloads, let mecall me I click on download. Now you see Ihave Django project.com. Slash download. Thisslash download is another URL. This Djangoproject is calm, the main one is the mainURL as the URL when what the user should seewhen it enters our site. And we are slashdownload because I know that URL, we haveto configure all of these inside our Djangoproject that is what is called URL routing,or URL mapping, or URL configuration. I cancall it anything. So to start with, theseare not going to come into my app, and thenin my app, but what are the URLs file. Sowe're gonna create a new file and name iturls.pi. And we need to import something fromDjango called path. So say from Django dotURLs, import path. Now this part is goingto allow us to us multiple URLs in our list.So we're going to have a new list called URLpatterns. And this list is going to take allthe URL we have in our project. So we cansee path. This is how we specify a new URL.And then I just have to I think there's acalled codes or whatever they're called. Andthen now I say views that index I'm goingto explain all of these, and then name equalsto index. So we import a path from Djangodot URLs. That is what allows us to configureeach URL you can see we are using the pathsthat we imported. And then we just have anew list named URL patterns. And then we havemultiple Like, if you want another URL, youcan just add a new URL new arrow like that.That is to shoot is a list. Now let's usepat on open a parenthesis. And then we havethis empty quote or Yeah, I think, then oneis empty. That means that is the root URL.Let's say we have something like slash download.Slash download now means that when a usergoes to our website slash download, then thisis what you happen. So but for now, when it'sempty, it means the comeback, just the mainsites, a main project, where we say slashdownload is miss our site slash download.So for now, this is the main site, and thenviews dot index. So the way you are worksin Django is that we enrich your recipe file,we configure the URLs, but when a user comesto this particular URL, what will happen?Now that is going to be done in the viewsdot index, we may render an HTML file, wecan just send a restful HTTP response, a JSONresponse, we can do anything. So that's goingto happen in the views. But before we canuse that views, we need to import it. So wecan see from imports, permission is correct.Import views. So now that we have views imported,we can say views dot index, what does thisindex mean? It means a function. So theseviews we imported is basically just as views.pyfile here, when I come here, I have a newfunction named index, it does take a request,I'm also going to explain all of this, andthen I can pass for now. So right here, Ihave a function named index. So whatever wedo in this function is one is going to beassigned to this particular URL. So this isthe way it works, the user comes to this URL,and then it sees that it needs to go intoviews, and look for look for a function ora class or whatever called index. And thenwhatever is done in that index is what isgoing to be rendered to the user. And thenwe're just going to use name, you can makethis name anything you can name it index orown, but is advisable to name it the samething, your name in that particular URL, soyou don't get confused or stock, or just getsome kind of errors. So this name is alsogive this like a kind of ID is the name. Solater, you're gonna see why we will give aname for now we'll leave it like that. Solet's save this file. So as I said, most usercomes to the UI is gonna go into views dotindex. And then whatever we do in this inthis is what is going to be rendered. Nowwhat we just want to do see is what am I justdoing here is what is going to be lender let'sdo something, let's return something. Andwe can just return an HTTP response. So thatbefore we can read out, we have to importit from Django URLs from Django dot HTTP,import HTTP response. And now say return HTTPresponse. And then this HTTP response isn'tgonna be can be like an just an HTML tag,like an h1. And then it gets a welcome. Andthen we can close that h1. So we were justhaving a simple HTML code inside this. Now,if I run my project, I'm also going to showyou how to run your Django project. If I runmy project, you're going to see that we don'thave anything. So let's first of all, runour project. Before we continue. Let's comeback into our command line and say Pythonmanage.py run server. Now remember, I saidwe're gonna use money Wi Fi a lot in our commandline. So for us to run our project on ourlocalhost, so we can see what we are building,we need to press Python manage py run server,I'm gonna hit Enter, and then you're gonnasee what's going to happen is going to runour project in localhost with a port of 1000.So we don't need to copy this. coming to ourbrowser, and then just paste it. So as youwait for that to load, so you can see whatit shows us what he shows us, right, he hasa default Django template of a new project,to create a new project and just run it, thisis what you're gonna see. But obviously, wedon't want to see this. What we want to seeis our own website, our own templates, ourHTML file, our response, whatever we wantto do. So now, let's come back to Visual Studiocode. We've done everything here. We've saidwhen a user coming to the homepage shouldgo to the View does indeed And interviewedat index, we're just sending an HTTP response,which is a welcome to this year is supposedto show a welcome Wiener. Now this is becauseeverything we've been doing sees as beinginside this app, this my app. But rememberI said my app is just a subset of the mainproject, we also need to tell the main projectswhere to look for the own URL. So that isour is going to see it. So what we're justgoing to do is to come into my project, writingURLs dot p y, we're gonna, first of all, importsomething named include. So from Django dotURLs, import path from Django dot URLs, wecan also import include. Now this is goingto allow us to include a similar URL froman app path, just like we're making anotherURL, same thing. For righty now, we're notsaying views or anything, since we're alreadyconfigured that in the app, but I was gonnasay, include my up those URLs. So if you knowPython very well, you should kind of understandwhat this is doing here. What is doing isthat is including my app that URL, so it'sgoing to go into my app right here, that URL,which is this URL file, and it's going tolook for a similar URL to this. So anyway,with the series home, what is being done there,what is going to be rendered. Now we got quittedthis. Now we'll come back here it refresh,you're gonna see now that we have a welcome,we don't have that default Django template.Again, what we have now is this particularage to this particular HTTP response. So thatis basically out to do a basic URL routing.Nowadays, most of these URL routing that we'regoing to talk about later in this course,is how to just basically do a simple URL routingin Django. To this point, we have seen howto get rid of the Django default templates.For one, we just create a new Django project,that template I was going to show you seenow to get rid of that and input our own response.So as you can see, right, the agent says,Hey, welcome. That was what we did, right?in Visual Studio code, we just returned asimple HTTP response with an h1 HTML tag sayingthey welcome one. Now, one more than this,we can code all our HTML in here, we can putall our P tags are law firms, if you knowHTML very well, you know what I'm talkingabout the guys that everything he wants tohave our own external HTML file, which wewant to render, when a user wants to accessthis index page. Now, that is easy. Djangois quite easy. What we just need to do, weneed to configure Django to be able to seeour HTML files to be able to see our templatefiles, or to be able to look at those files.That's the right word. So when we requestfor less index dot HTML, Django knows whereto locate that file, and then it renders it.Let's do that quickly. As closes up, closesup also. So right here in our root directory,remember I said the root directory of a Djangoproject is the directory which contains themoney does b y file? Night, yeah, we're gonnacreate a new folder. Now this folder is goingto be called templates. And in this folder,we're gonna store all our template file. Thatis all the HTML files we're gonna use in thisproject. What if I just stole my templatefile right here, and I come here and I say,okay, Django show index dot HTML. We justcreated a temporary file. But we didn't tellDjango that this is where it has to look forindex dot HTML, or whatever template filewe're using. So we need to tell Django thatwe're going to do that by using this settings.pyfile in our project folder. So we're goingto have to open settings.pi and then we'regoing to scroll up. And then we're going tocome, let's just make this full screen righthere where we sit templates. This is the configurationfor the template are going to look forwardwithin this. So this is a short form of directory.So a saying which directory should Djangogo into to look for the template file? Soit is very easy since we already have thetemplate for the year. We're just going tosay base there. Comma, and then we're gonnasay template. Now this template must be thename of This folder. So what we're seeingis that it should go into the base directory,which is also the root directory, and lookfor a folder named templates. Now, let's saywe named this template without an S, we alsoneed to call me I removed that as an emptytemplate. So whatever you put here, must correlatewith whatever is the name of the folder. Now,we can just save this. Now Django knows whereto look for our template files, that justcloses up. What we just want to do now isto go into that template folder, and createa new file named index dot HTML. So in thisindex dot HTML, we can have an h1 now witha normal HTML file in a normal HTML file,and then we can just say, let's say are youdoing today. So in our views, now, we don'twant to be returning this HTTP response, orwhat to do is to render this HTML template.Django knows where to look for the templates.Everything is simplified. Now, we can removethis HTTP response, I say return render, istaking a request. And then you just put indexdot HTML, which is the name of the file, ortried to render, which is right here. So wehave our function index, which is having arequest, now it retorted returns is that it'srendering index dot HTML. Now let's save thisfile. And then we come in here. And then wehit refresh. So this should change this back.So it doesn't change right here. Let's seewhy. It's gone. Yeah. And made sure. Breakout of the server. And then let's run it again.For let's get a minute to run. And then let'scome here, and it's refresh. So you can seenow it says are you doing today? So this showsthat it is coming from our index dot HTMLfile, not from an HTTP response. Now, thereason why it didn't load before, I'm surethat it has been cached or something. So whenwe opt out of that Django away, we close theserver and we started it again, it reloaded,so sometimes you might need to do that. Soyou see now it says, How are you doing today,we can just have an image. In here, save it.We have that saved. Okay, it's refresh. Andthen you can see that that image, so is typicalHTML, so we can close out these now. So nowyou've seen how to render an HTML template,or template file in a Django URL. So up tothis point, issued starting to understandhow to work with Django, how to create a newproject, if you know the difference betweena Django project and a Django app. If youknow how to go about the URL configurations,you should know how to set your views functions,then you should understand the Django templaterendering. Now wants to talk about sendingdynamic data to your template file. I'm goingto explain what I mean by this. Let me comeinto my Visual Studio code. Right here, Ijust have the plain Tex named our you're doingLet me explain the difference between staticand dynamic and when something is studied,it means 88 is the same. When something isdynamic, it means it changes to a particularletter to a particular function or whateveris given. I'm going to explain these morewhen we're doing the practical things. Nowthese How are you doing? It is static is justa static text right? Now we say that becauseif I reload this page is there there is itis not changing. It's just there because that'swhat I gave it. When something is dynamic,it might be like a variable is different foreach user. So just like when you come intofacebook.com, you see your name they can saywelcome Tom does for if does your name. Andthen if someone named john login, you'll seewelcome john. But when you go to Facebookand you see your newsfeed you will see newsfeedof your own Free is not the another person'sfriends, or there are countless ways you canthink of it. So that is what dynamic stuffis. Now, that's apples because of it is actuallythe same page, like the same HTML file, orthe same whatever the same code, but is differentfor each user. And that is what we mean bydynamic when something is not the same foreverybody. So we're going to talk about sendingdynamic data to our template file. What Imean is, in Django, because Django is a backend framework, we implemented some programmingfunctionalities in the HTML, some things likevariable, something like if statement, somethings like for loops, we're able to codethat in HTML, using some particular language,some is a template language called Jinja.We're going to talk about that later. Fornow. I will I send this, whatever I call itthis dynamic data to my file. What I justneed to do let's see, I have a variable calledname. I'm just saying this name is john. Righthere, I can see. Welcome. JOHN, let me justsee, john, CV. Fresh welcome, john. So thisis static, because it's john, if another personnamed Tim login, is going to say, john, ifsomeone else name rules login, is going tosay john, was he will call me and now let'schange his name to like Patrick. I can sendthis variable into my index dot HTML file,and I can access it from you. I can do thisby just coming after the index of HTML, youjust add the curly braces, and then the nameof the variable name. And then we're givingyou this name variable, which we have here.So this is like the key of value. It's likea dictionary, this is the key, he says thevalue. Now I'm going to be able to assessthis variable, because of this key in my indexof HTML. If I come here, now, instead of saying,john, to assess that, I'm going to use thecurly braces twice. And I'm going to say name,if I save you right here now, so as you cansee, now, it says welcome, Patrick. Now, thisPatrick is coming from our back end is notcoming with just as a plain text, right here,we are saying name, but what is printing thereis Patrick. That is because that is what weassign deeds rights here. Now, this can bedifferent for everybody. When we go further,you're going to see how we're gonna use authenticationto allow each user to have their own data.Now, let's say this data is coming from adatabase. Let's say we log a user in, andthen we get this name. And let's say it wouldbe something like user dot name, I show thisand something like user name. So now thisname is given a value of user dot name, whichis now coming from the database. So it's intuitive,it will be different for every single person.So is john are logged into St. JOHN, visitingthe login his theme that will be sent intothe front end. And as always send dynamicdata using Django in Django? Well, now wecan also send, make this more formatted. Likelet's say we have multiple, it's not a goodpractice to come in and do comma and say,age, and then give it know that you can alsodo that. But that's not a good practice. Sowe can just have something we call contextdoes popularly using Django, and this contentis going to be a dictionary. In this dictionary,we're gonna just have all the fields one ofus listen name. And then we just give it Patrick.And then I say age, we can give me 23. nationality.We got some British, and then we can justcontinue like that is basically a dictionary.And then if we want to pass this into theHTML, we don't need this curly braces again,we can just say context. Now this contestis being sent to this index of HTML for recallme and now I will say name is going to printthe name that is in here, which is still Patrick.So that didn't change. Say welcome Patrick.And Ella, just give it a break. And then wecan say you age years old, So now let's eatrefresh, I see says you are 23 years old,which is the variable age coming from theviews. Well, we can also use a nationalityand say you just give it a nationality. Iwill call me on it refresh and says you areBritish. So this is just how to manipulatethe data. As you can see different data comingfrom the back end coming from the views arelater Well, I'm going to show you how to getall this from database, not just you typingin dummy data or static data. Now, I hopeyou understand the concept of sending dynamicvalue is from your views to your templatefile in Django. Now, we're gonna take someof the features we've learnt in the previousparts, and then with some new features, andthen we're gonna use it to build a very simpleword counter in Django. So is just a verysmall projects, way in which a user is goingto be able to put a couple of words thereare like a sentence or an article, and therewas the user ID summit is going to show theuser the amount of words that are presentin that bunch of text. So let's do that. Thefirst thing we need to do, let's quickly cometo our server, which is running right here.So we want to have like a form right here,which a user will be able to put all the textin, and then we should have a submit buttonbeneath it. So let's do that. First of all,writing VS code, we can get rid of all theseright now. And then we just have a form canjust leave it blank for now. Okay. So in thisform, let's have a text area. Give it a name,or message text. That should be fine. Andthen there's our Submit button that I shouldn'tbe Submit. But yeah, we can have a break.So now let's save this on it refresh righthere. So this is just what we have. Now, let'ssee, we can add something like rule rules.And then let's say just to give it again,longer, I think there's something that comesclose. Give it 10. Also, wait, refresh. Okay,so let's make this like 2525. Wait, refresh,good. So let's make this a little bit bigger,a double of 50. Let's see. Okay. So I thinkthis is good. And then right here, we're notreally specific about the design, we justwant to know how to add the back end functionality.So let's come up here above the form, right,is have an h1, which just says inputs, yourtexts below. So now, this is our form. Let'srefresh and just see. So this is our formright here. And then this form, let's giveit a method. If you know HTML, you know thatthere are two methods when you're submittinga form, which is get under post. So we'regonna leave this blank for now. And we'regoing to talk more about get on POST methodwhen you're dealing in Django. So we're gonnatalk about that later. But for now, we'regonna leave this blank. So what wants to donow is that once you get up to the text here,and it's submit, not the URL, we're stillin this URL, this page, and then it just passessome data, everything which was written inthis place when it's submitted, which in anotheris passed into the URL, and is saved in likethis variable, this key named text. And thereason why I saved in text is because we gaveit a name year of text. If we give it a nameof words. I will come here into fresh I'llsay, are you doing, and then we call me outon it. So meet, you see, now you save in avariable key of so meet with all these values.So now the oddest is being passed to the URL,it's very easy for us to now get all thesevalues in the backend. So let me explain whatwe're going to do. So once the user hits submit,we want to send it to another URL right here,you can see that it's just sending back tothis home page, we're gonna create anotherURL, maybe like a counter, maybe like slashcounter, that URL is going to count the amountof words, and then he's going to send himback to the template file, and then showcasethe amount of words for us. So it's goingto make sense in a bit. Let's just do that.So first of all, we're supposed to have anAction. Action is where we want all this datato send to. So now we don't really have anyother URL, let's go and create that. So righthere in URLs of p y, let's have another URL.And then we can just name this counter. Andthen let's say views those counter. And thenlet's give it a name of counter. Now, youknow that we said view dot counter where wecome into our views, we don't have any function,the name counter, so let's go create that.So right here, just want to have a new functionnamed counter. And then wants you to takeyour requests. Now, we can also return renderrequests. And then want to have just a waywe have index HTML for this page, we wantto have another HTML file for this counter.Let's come here and just create a new fileand name it counter that HTML. So that isblank for now, let's leave it blank. Now wecan render this counter dot html. And thenwe can leave that for now. So we don't needall of these again, get rid of that. So nowwhat we want to do, is that we want this actionto go to counter is very easy, we're justgoing to do in action, we'll just put thename of the URL, which is counter. So nowonce we eat some meat, it takes all this datato this counter view. Now let's go to is thehouse become your eat, refresh? Okay, no,not like this, and then a What's up, thenwe need to submit. Now you see, it goes toslash counter. With this words, I say, what'snow that this counter as this particular data,these yo yo can get that data. So first thing,get this data, we're gonna come into views,we're gonna have a new variable, or let'sjust name this new variable like words. Andthen first, to get it to see requests thatget getting worse, I'm going to explain allthis. So what we're just doing now is settinga new variable, and there was a request doesn'tget. So I want to send a request to whateveris being passed to this particular view. Andthen we want to get it so and then what wantsto get is this words, now we come to the indexat HTML, you're gonna see that we're sendingthis particular data into this counter. Andin this count our getting that data. So requestdot get words why we have this word is becauseit is the name we gave the particular textcollator, like the text area, which collectedthat data, this is the name assigned to it.Now we change this to text. What we want tobe now should be text. So let's just changeit to testicle does looks more makes moresense. Now you see that, once we are collectingyes should be the sandwich was easier to becauseas a name assigned to it every changes tolike t x. Now this can't, when we try to collectdata from it. It doesn't see any form withthe name of text. So it's not going to collectany data, give it x is going to collect ourdata. So what we can just do now since wealready have that data, we collected our dataand stored it in this variable named x. Sowhat's going on now let's go back to the oldway We just write some stuffs. And then wehit submit. Now we collected our data. Andthen this data a revise after it is now storedin this variable named text. So you know,in Python, you can, there's a way we can countthe amount of words present in a text. Solet me quickly open up my command prompt hereand show you what I'm talking about, thenwe'll come back here. So let me open my pythonshell real quick. And then let's say I havea variable named text on it as a sentencenamed a. Oh, are you doing. So you can seenow that this is 123455 words in it. Now wecan count this by, let's see, we can justprint it straight, and say, length of sexdot splits. So what this is doing is thatwe're just printing the length of text, thesplits, the splits means you get each wordpresent in this text. So once it's split everythinginto one different value, then you're goingto count the amount that is in the event.Now. Let's do that again. Okay, so that isbecause I didn't close the print function.So let's just get out of there. And then onemore. So now you can see that we have five.So that was because this print is for thiscloses and these lenses for these and thesefor the so we need to add one more. And that'swhere the show works. So now you see thatit's Prince five, that's because we have fivewords here. So does exactly the same thingwe're going to be doing right here in ourproject is already our word to use our routesstored in this variable, by just going toadd a new variable, I will say amount of words,we can name it like. And then the amount ofwords will be the length of text does pleaselike this. So now we have the amount of wordspresent in what the user root. And we studiedin this way we named amount of words, whatwe can just do now is to send this amountof words straight into this counter dot html.Very easy. Just have a key and a value, whosay amount of words to say amount, and thenwant to give it amount of words. Very easy,we'll save that. And now we can say the amountof words is, and then what is the key, thekey is amount. So this is the key, this isthe value. And then we use the key together.So the amount of words is this. Now let'sgo back. And nowadays writes full text thatmakes sense to say, A, you good. You are doingwell. So let's count these 1-234-567-8910.Now we hit submit. And he says the amountof words is 10. So you can see now that itsays the amount of words is 10 does exactlywhat we want to avoid. So let's just comehere and just give us back an h1 copy, save,visit, refresh, and I see see the amount ofwords is 10. To read just go back and addsomething to remove these and now we shouldhave 12344 with submit it says the amountof words is four. So now you can see as we'restarting to turn though these are featuresI notice Django stopped our learning intoproject. So you can see now we just get thesimple text counter it counts auditors. Nowthis can also be very useful. You might seejust a simple project where sometimes youcan beautiful personnel use if you have likea blog posts. So let me just open up a blogpost. And then you can copy all the text andthen just paste it in to list take somethingfrom here. And then we can just copy all ofthis tray. Okay, there's a bunch of code.You get what I'm talking about. Then we comehere, paste it in. And then we hit submit,and it counted for stereo Jan 28 words. Soyou can see that it's also very useful. Sometimeswe just need it. So right now we've done this.So, but there's something I want to talk aboutmore invites submit, you'll see that everythingthat we wrote in that text area in that textwas, it's been sent into the URL, and it'squite lengthy. So as you can see a lot, that'sa lot. And that's the reason why we're ableto access it. But why we don't want all thisto be in the URL, what do we just want itto be slash counter. And it's still goingto be able to count this text without havingall this in the URL like this. Without havingthis, we just want this, and they want tobe able to count. So we're also going to talkabout that more in the next part. Now let'stalk about GET and POST requests. So in thelast part, we'll build the simple word countout where we'll be able to put a bunch oftext. And then once we hit submit, it countsthat takes for us, we are going to noticethe other text in which was submitted is beingpassed in this URL. Now, let me explain whyall this happens. If we come back to our code,right here in our form, you're going to seethat when we specified metode, we left itblank. So this method is for you to know thetype of request you are using the type ofmethod you are using in this form. So it'seither a get method or a POST method to thoseare the two types that are being used. Anda get method are mostly used whenever we arenot passing any personal information or anyvery safe information. Because as I said,it is being shown in the URL. But it was ina POST method. This app, when we use a POSTmethod, the information in which was sendingis not going to be shown in the URL. Now thisis mostly used, because it weighs in againmatters, let's say for when a user wants tosign up to a website, we don't want to passthe user username and password right herein the URL down to make sense, or user wantsto pay online with his credit card, we don'twant to put the credit card details in hisURL. That's why we use POST method becausethat is more safe. And it prevents some attackson our website. So right here, as you cansee, it was blocked, I didn't specify anymethod. So when I live in blank like thisin a default automatically, it uses a getmethod. So if I don't put any method righthere, but I just put a method and don't specifyit, it automatically uses a get method. SoI can also call me I just tried to get thatis still a get method, or I leave it blankis still a get metal wave. Now I want to usea post metal I need to put that year is postI want to use. So I'm going to do two posts.So now we're just going to build this wordcounter again, but now using this POST method,so you get the concept of post. So now ourchanges to post method. Let me save this.And then go back here and hit refresh. Sonow we will put a bunch of texting. And it'sSubmit. Yeah, so right here we have this arrow.Now it says forbidden CSRF token verificationfield, request aborted. Now this happens becauseas I say a POST method is used for more personalinformation. And anytime Why isn't a POSTmethod Django expects us to use somethingwe call CSRF token. Now CSRF stands for crosssite request forgery. So it's like an attack.Now when you're passing data through URLs,an attacker or someone that has bad intentionon your site can tap into those and get thoseinformation by using this CSRF token. Djangoprovides a default CSRF token which allowus to prevent that attack. So let's just quicklylook it up CSRF token. So this is going tocome up as you can see CSRF tokens a uniquesecret unprintable value that is generatedby the server side application and transmitted.So this is just a boring definition of it.But that is what the CSRF token does. It preventsthat so let's open up the CSRF Yes, CSRF attack.So, let's at Yup. So in a CSRF attack, aninnocent user is tricked by an attacker intosubmitting a web request that they did notintend. So is like stealing information. Butwhen we use CSRF token, it prevents that.So I hope you get what that is for. So ifwe don't use CSRF token in Django, it won'tallow our form to work. So we need to addthat. So it's very easy, just a line of code,or we don't need to do is to put two curlybraces to percentage size, and type CSRF underscoretoken. Now, when this is done, everythingis fine. If we go back, does it refresh, asputs these in a new we click Submit? I'm verysure an error is still gonna come up. Yeah,so it says multi valued error, slash counter.So we have an error. But now it's not. Becauseof our post request. We've covered everythingfor this. So this is how to do your post method.But why we're getting this error is becauseright here in our views, the poi, you're gonnasee that we say we want to get what the usersent to say request dot gets. But now we areusing post. So we also need to do the adsand just say, requests, dot posts, is thateasy. No, let's just go back fresh. As weput that to reload, let's come back, the garbageis running. Because it refresh. Now, withtype three, knowledge, it's amici. Say itsays the amount of words is three, and thenour URL is completely clear. We don't haveany information being passed in our URL. Sothe POST method is very, very useful wheneveryou are dealing with some more safe and secureinformation. So I hope you understood thedifference between GET and POST requests orPOST method. Let's talk about static filesin Django. Now, what is this static filesin Django we're talking about is any externalfile that you use in your template file. Now,template files are the HTML file we use inDjango. So this index of HTML is a templatefile. This is a temporary file. Now any externalfile we use is our static files. Like do wehave an external CSS file that is linkingto this HTML file, that is a static file,if we have an image, we have an external video,all those are static files. So just the waywe configured for the template file, remember,earlier in this tutorial, we actually go tothe settings of this project, and we are totell Django where all these template filesare located. Now we have to do the same thingfor the static file. Let me close this up.Let me close all of this. Now, let's say wewant to add an external CSS to this page.Let me just remove this form, we don't needit again. Let me say, a welcome to my projects.Now, let's say we want to add an externalCSS to this particular file. And then we wantthat CSS to be linked to it. In a normal HTML,we don't need to use our link tag. And thenwe just specify where the CSS file is located.Boring. Jango is quite a bit different. Justthe way we store all the template files ina folder named template, we need to storeall the static files in a folder named static.Now let's do that. Create a new folder. Iwill say static. This static file, as I said,is going to contain all the external fileswe need. But now we need to tell Jango whereto locate all the static files. And then we'realso going to do it in the settings.py file.That's why I said earlier in this video, thesettings.py file is like the bedrock of thewhole project. It is very useful. So whatwe're just gonna do now is to come right intomy project, and then go to settings.pi. Sothis was where we configure for the templates.Before the static files. We're going to configureit down here. But before we come down, wehave to go up first of all, and they're righthere, we need to import something we've gotOAS. So let's type inputs OAS. Now what thisalways does is that it gets a specific theoperating system of which we're coding onlike, oh S stands for operating system. Sothis gets you on a Windows only mark or whateverwe are on. So now that we have imported OS,but we just want to do is go Going down. Rightbelow static URL, we can have something thatgoes static files, there's static static files,underscore days with an S are going to sayequals to open a bracket, I'll say who isthe path, the join, and then open anotherbracket on the same page. And then we justleave like a comma, static. On the right,you also live in a coma. So what it is doingis, is from r o s is going to do base directory,which is also the root directory of this project.So when I say the base there, I mean the rooster.So right here is the base directory, the folderthat contains the money.py file is a basedirectory. And then is going to the folderwhere we have static. So right here is thatfolder. Now we have that set up. in that folder,now we can create a new file and name it styledot CSS. So now we have discussed style, theCSS, let's style this h1 and give you like,color of red. So you can say h1 is say, color,red. So we have that. And now we have to linkthis static right here into this HTML. Wedo that on top of the file. And then you know,in normal HTML, what we just need to do isto say, link, and then we just say real datasheet. And then we just say, F, and then wejust give it like style dot CSS, the nameof the file, and then we close the file. Now,if I save these, and I come here, and it'srefresh, you'll see that we just have thattext, which is in black, and then the CSSis not reflecting on it. And that is becausethis link is not seen by Django. This is toodetailed, we're gonna use both in this HRF.Instead of just writing styles, we need toadd something we call static. First use ourstudy. Before the name of the file, we'llput a curly braces, a percentage sign, nowrite static, leave a space, add one of thecodes, we'll close it right here like this.So this is how to use static. So like this,Django should see should know where to locatethis style dot CSS. Now receiving a copy ora refresh, we're going to get an error, atemplate error. Now we see it says templatesyntax error as slash. It says invalid dataon line one, did you forget to register orload this tag. So now it's saying we forgotto load this taco static. So right here, thisstatic way, it's like a tag that Django sees.Before we can use a, we need to load it. Sothat's very easy, we just got to the top ofthe file. Whenever I want to load somethingin Django, it needs to be at the top of thefile. And we'll say, open and close curlybraces, percentage sign and load static. Nowwhen we save this, we come back and it's refresh.Boom, you see now that it shows it in a redcolor. That is showing that the CSS is workingon this HTML file. It is connected to it.So let's go right here and just change thisto like blue. we'd save weight refresh, yousee now that is blue. So that is how to linka static file into your template file. Butnow let's go further. And then let's workon more real projects. So what I want to donow is just go to Google and then downloada free HTML template. And then I'm not goingto show you how to link different types ofstatic files, not just only the CSS now elimelechimages may be JavaScript, anyone we download,so I didn't prepare for this. I was gonnasearch free HTML templates and anyone we see,we're gonna use so let's see. Let's see. Ithink this should be good. And then loserscrew down. Okay. Let's see. Check them out.Yep. So one of all of these should have alook. Okay, this should have a lot of CSSin it. And then we're just going to downloadit. The free one. Scroll down. Okay, thisis a free, let's just scroll all the way upunless a free HTML template download or something,and they just get one to download on the legendsas you know, Django project. So we shouldhave a free ones actually. I know one sites.So bootstrap me. Yep. But this website, Iknow they are free. And then they just comehere and get one to download. Jump Jump onthen. Let's see. So let's work with this onepage, download. Pre download. bootstrap fivedoes download while subscribing to the newsletter.So let's see. Okay. It was downloading righthere, as you can see. Okay. Give it a second.And then that should be done. Okay, so let'sgo to the Downloads folder and look for thisextra, and then drop it into Visual Studiocode. So we'll know our gonna use it. So thatshould be done downloading. Let's come here.Go to downloads. Page. Yep. So right here,we can just drag this or we can just copy.And then let's go back twice, or three times.And then so right here is the our Django projects,we'll paste it in there. That should takea few seconds to base. So now we can closeall this, we don't need all this again. Nowwe can just start with what I say we're goingto do changing different or connecting differentstatic files into our projects. This is done.And then this will open it up. So we haveall of these right here. Good. Now we comein here, we should have that one page here.And then we can delete this index of HTML.Let's just delete that. And then from year,one page where we have index HTML, let's draginto the templates for Yeah, we move in thenow that we are moved, we moved that nextthing we want to do is to just move this assetinto the static file, because that's wherethe static files are located. So as I said,we see the CSS image JavaScript here. So let'sclose this one page for now. And then righthere in index, this is what is going to berendered when the Index page is called indexdot HTML. So let's close this up. And nowlet's go back to our project, and then itrefresh. So you can see the title is changed.And then we have all of these. So you cansee, it is linked with the age the staticfiles, but not seeing the way Django recognizesit. So all these are linked, but not the wayDjango recognizes them. So now let's justdo change everything we need for this file.Does gonna come here and do node static. Andthen let's start from year and then can actuallymake it quicker by using the boats like these.Anyway, we see this we just put it in there.So we judge the odds. A good trick I use andthen we do the percentage sign space static.And then we put this right in here. And nowwe come here we do the same thing. Now wedo it right Near the end of all these files,and then we just close a percentage are close.So now if I save these, and I come here andeach refresh, I should see a massive changein the website. So you see now we have thepre loading, tag, or div tag, style or whateveris loading. And then our page should loadas expected. So that's loading for too long.And I'm very sure is because we've not linkedall the files, we were supposed to link measurescopied this static analysis, continue linking,we continue linking. So let's see the scrolldown. So now when we come here and into freshtissue work, and it shouldn't load forever,good. So now you can see that this is whatwe want. Right? Yes. So we can see that thewebsite loads successfully. So this is howto basically take a template file, then itwill the static, it might the static filesmight be linked differently, or doesn't useit or link it in Django. Now, I hope you understoodeverything we talked about in static files.So now let's talk about models in Django.So in Django, we have something called themodels. And these modules are mostly usedin configuring our database. So most of thetimes in Django, you don't need to write asingle line of SQL code to get your databaseup and running. That's why we have somethingwe call model view template. So the modelis what we use for our database, the viewis what the user See, and the template isright, all this HTML. So from the model, wejust pass all our data into our template forchildren understand all this in a minute.Now, the models is very easy to configure,instead of using like a date, a database tableSQL code, we're just gonna use the classesin Python to build our database. For now,we're just gonna be talking about the classesand inheritance in the view, then later on,we're going to move to our gonna integrateit into our database. Let's go into a filecalled Moodle dot viewer. And these filesis always located in our app. So right herein this file, we can create a new Moodle.So by just creating a class, and then we canjust name it, whatever we want to name it,let's say like, let's come into this comeright here. So let's say fixtures right. fixture,and then we can use this like this. And thenwe can give this like an ID of which shouldbe an integer. And then we can have the nameof the feature, which you want to be a strange.And then we can also have something like thedetails, service details. We should also bea string. So right here, what we know is thename, we have an ID and then the details ofthe fixture. So we have this right here now.Well how can we use these in our views isalso very easy to just need to do is to comeinto our views.py and then right here in theindex, where we can just do is to first ofall import that model from you. So we cansee from those models import feature. Nowthat we have that imported Well we can justdo is to say, let's say feature one. Shouldwe curse shoo inherit from the feature model.So now that this feature one is inheritingfrom the feature model, we can now easilyspecify the detail of the attributes of thisfeature. So we can see if you join. But Id,let's give it an ID of zero, and a featureone. Name, let's give it a name of say, fast.So is a feature. I remember that this is astring. And then we add one more, which wasI think details as details. So feature anddetails. Let's say, service is very quick.So now we have this year, where we can justyou know is to pass this into the index ofHTML. So we can just say, feature should beequals a feature. Let's see. Now if we comeinto index at HTML, and then we look for these.So this should be beneath the Get Startedof this, let's crew all the way up. And thenyou get started. So that about a minute ago.Scroll down a little bit. So we should seeI get started. And then yeah, right here,we have this. So instead of Lorem, or whateverthis is now, we can just have feature fixture.This is fixture I regard here as drag justbeside this because I've ever needed an alert.So this is fixture can see a feature that'sname. Once we hit Save icon here and it refresh,what we should be having now is the name,which is fast. So let's wait for this pageto refresh. So now you can see what we haveis fast, we don't just have whatever was thereagain. And then we can also change the detailsof dat. So let's delete all of these. Andthen we can say feature. A feature the details.And then if we come here, and it refresh.You see it says all services very quicklyas that detail. Now we can also do the samething for all of these for what we can dois to come into our views. So we are featureone, we can just copy all these bass, bassbass. Okay, let's take two bass bass. So nowlet's just change out these two feature two.And then let's change all these to featurethree. And then all the way to feature four.So now, we have feature 1234. And then theID should be 123. So this is fast. Let's saythis is reliable. Easy to use, and affordable.To now guys a service is reliable, is easyto use, and our services vary. So now we haveall these 1234. Well, how do we pass theminto the front end. So we can do the samething doing something like this. So we canchange from feature to feature one. On theright here we can just say feature two shouldbe feature two. And then feature three shouldbe feature three and then feature four shouldbe feature four. And then we got come righthere and assess it right here. And then wecan just do exactly the same thing. So wechange this to one, which one take us away,Sunday is just chain DS and then no featureto feature to the details. They receive itnow on Comm. You see that right here, we shouldhave the feature to the details. So see fastservice is fast, reliable service is reliable,I see that these data are now coming fromour views are coming from the back end. Solet's just do the same thing here. And thenyou can see, I'm going to show you a false,or something that we can do to make this quickerand a better process. So I know why I'm doingall this from scratch. So we have featurevery, and then the details. And then we havethe same thing right here. feature four. Righthere. We come down, it's your fresh data,in which we add right here. I was I've beenrendered right here in the view in the template.But I'm sure you can, we are gonna agree withme that what we just did was time wasting.And let's say we want we have 1000s of datais this how we are just going to render themeach. And it's not possible to make this dynamic,right. Because this is obviously static datais just whatever we're passing from the databasefrom Yeah, is what is shown here, we can makethese more dynamic. Now when I mean more dynamic,we know we can have just one bunch of code.So you can see that this code is repeatedfour times in our HTML, we have it here 123.And then we have vgf. For now let's cancelthis for as cancelled three, or leave justonly one. So we can see it was repeated fourtimes. But now we cancelled everything outleft only one. If I save it and call me andeat you fresh. And then I see that I haveonly one. But I'm going to show you why Idid this in a minute. So let's come back hereinto our views. Instead of having all theseJoe just pass in here, like these featureone, feature two, this is probably not a goodpractice, what you can do is to have a list,I can name it features. And then we're justgoing to purchase feature one, feature two,feature three, feature fourth. So now thatwe have all these four, you can just do. Let'sremove all of these, which we passed. Andthen let's come back. So instead of featureone, we can just see features, and then wecan pass this features. So now what you seenow we have a list that contains all the datawe have. So all this data, which we have here,they are stored inside these lists, namedfixtures. Now this is a very good practice.And this is the way you should do it. Andnow we are just passing it to the HTML withthe features and features. So now when theHTML, we can look through this list and getthe attribute for each of these lists righthere, so feature for us all these attributes,Victoria, all these attributes. So from theHTML, we can look through a and get all thoseattributes we need. Let's go there and seethe safeties. So right here, what we're gonnado, we're going to look for that particularcode block, in which we want to loop through,so we want to loop through these particularbooks. So is the amount of data we have. That'sthe amount of books that we show. Now, ifyou can reason that way, where you see thatthat is now dynamic, in depending on the amountof data we have that shows the amount of textsof card or block being outputted. So and thatis this block of code right here. So we cando something with a for loop. And then wecan see for feature a features. So what I'mdoing is this features which I passed in HTMLis a list. So I can look through the listit is ethereal. So I can say for feature infeatures. So instead of feature one dot name,I'll say, feature that name, and feature thedetails, just the way we do in Python. Andthen what we also need to do is to make surethat we end our for loop right here, by saying,and for because you know, in Python, the forloop is being ended automatically by usingindentation. So if you get what I'm saying,for example, if I come here, and I've folio,so I'm going to have a fixture in fixtures.So now when I just do something I can justpass for now. So anything under this indentationis under this folder, promise I've come outof the indentation of continued coding, thefollow up is being broken. So only this blockof code now is part of their for loop. We'rein HTML, we don't see indentations, what wesee is just code tags and code blocks. Sothat is what we also need to use to enterour for loop. If we don't put an for loophere, what is going to happen is it is goingto loop through all the watch code below these.And they are going to see all this code multipletimes we're going to get all the images multipletimes. And it's not what we want. So let'sgo back up here. And then this ends the forloop. So now we look through that, and thenjust get each of the image each of the namesand these, I will save it. Now when we comehere at refresh, you're gonna see that thiscode, this block is going to appear four timesto see fast, reliable, easy to use and affordable.So now we're making it dynamic. This is whatwe want. So we have just only one code blockhere, one div tag here, but it's appearingfour times, because we are looping throughthat. And that's because we have four valuesright here. 1234. We also have one more, letme just show you the, from our back end dawe're good, we're not gonna touch the HTMLfile. But when we come here on each refresh,we're gonna see one more minute. So let'ssay we have fixture five. So let's use ourodds. So we are feature five, and we havejust asked for, and then what we can say trustworthy,just like our service is a few with trust.So we can also put that into the list. Sofeature five, and we save it. So now we justadded a new data right here in this our smalldatabase. And then I'm not gonna touch theindex, HTML, will not call me on it, refresh.Okay, so now we got office error, it sayslook available feature reference before assignment.So let's see where that is coming from. Sothat is just an error because we say fixturesinstead of feature five. So that is what weneed. And then we need refresh. So beforethat load, we can see now that we have a newblock here without touching the HTML. Butthat's how easy it is to make stuff dynamic.So now if we think about it, it let's saywe have all this coming from our database.That is how we can make our website very dynamic.Let's say we want to show a list of users.So once a user sign up automatically, justgonna add right here or something like that.You can just make do anything you want. Andso that is the basics of this models in Django.So let's do some more things that we needto know. So right here, we did a for loop.We're going to do an if statement, just likewe do in Python. We have the for loop wherethe statement we have the conditional STDFDS member. Let's also do that in our templatefile. So let's set something like in our models,let's have a Boolean. So let's say is corrector is true. So what these So I want us todo is, let's say is this features true, let'ssay is fast. Now we added a new attributes,which is just to show if our website is reallyfast. If it's true, then it should be true,unless there's a lie, and it should be forced.So that's just the basic stuff of what thisis for. Now, our website is fast, let's see,feature one dots is true. And then we'll saytrue. So this means that it is truly fast.And then they just do the same is truly reliable.So that's a feature to true. And let's sayit is not easy to use, let's say we're justlying about that. So now feature three isfalse. It's not easy to use and feature for.affordable. Let's make that true. Yeah, true.So now first of all, let's come here, refreshand get rid of the stress, worry. So, again,give that a second. Okay, so we just havethis. And now each of them have whether thisfeature is true or not, we can come here inour HTML and see, when beneath this detail,we can have a p tag that says, true. And thenwe can have just less of a p tag that saystrue. What if I saved these said this. Comeon, this feature is true. Now, let's savethis. And hit refresh right here. So you'regonna see that he says, This feature is truefor each of these features. But remember,in our database, we said, It is not easy touse for easy to use, it is false, but easyto use, yet he says This feature is true.So how can we fix this outcome we get witha fixture is really true or is wrong. Nowagainst the conditional statement. So we cansay if fixture.is true is equals to true,then we want to say the future is true. Andthen we can also end our if statement. Solet's do that. So to call it braces to percentagesign, and then we can say if that is true,is equals to true. Then let's say this pictureis true. And then we need to end that if statement.Just the way I told you that in Python usingthe notation to end our if statement and ourfor loop. in HTML in the template for we useda code block for the tag or whatever you wantto call it. So now only get in if this featureis true, does when it says true? So let'ssave it and go check. So we is refresh. Andnow we should not see true for a year. Okay,so as you can see, it doesn't say true forany of this. And that is because you know,in Python when you want to use an if statement,you use this columns. For right here. TheBoolean even in Python, we don't need columnswhen assigning a Boolean. No does not columndoes the parentheses or codes, I think thatequals So let's save this and this shouldwork. It didn't work because we put thosecodes. So let's hit refresh. And each of themshould say is true except for this. So hesays this fixture is true. This picture isDrew. He doesn't say anything and say thispicture is true. So we use Annie's data toget whether that particular feature is true.And note the fun thing that we're doing here.Everything we're doing is to under one codeblock, what is generating different data fromthat same one code block with different valuesis very fun and very good. Everything aboutit. But now right here is false. Let's moveon to our VA and see that this feature isfalse. How can we do that? Just in Pythonwe have the if we have the L statement, wehave the Elif elsif statement. We can do thatyear also. So we can say if feature is true.Else So LCM is if the feature is not true,then we just want to have this that says,Come on, that says This feature is false.So if feature is true, say true. Any featuresto else that means a feature is not true,that is obviously false, say this featureis false. Or let's come here and hit refresh.Let's see what we have. Now this feature istrue, true or false, which is what was andis true. Now this is very, very, very good.That is exactly what we want. And then wecan also use the LC in this. So right here,so they'll say else, we can just say a leaf.feature that is true. is equals to false.Now, this should give us exactly the sameanswer. Let's hit refresh. You see, it saysThis feature is false. So we can also usethe leaf statement or the statement. Well,most of the times want to use the Elif statement,and we have multiple conditions we want toset, but for this case is just two conditionsis either it's true, or false. So for that,we can just stick with the L statement. Soelse, if is not true, then is definitely false.Now, that is how we can do some busy dynamicdata rendering in Django. I hope it has beenfun to this point for you. So now I've introducedyou to the basics of the Django modules. Butobviously, all these are just normal Pythonclasses, which we are inheriting in our viewsright here. But we can make all these moreadvanced by turning them into real databases.First of all, let me collapse this and this.So if you come to this root directory, you'llsee that there's a file named DB dot SQL litethree. So this file is what stores all ourdatabase in Django. So when you create a newDjango project, it would define default automatically,you have your databases saved using SQL Lite.So as we know, the various database providerlike Postgres, Oracle, MySQL, secure light,like what is here. So, as a default, Djangouses SQL Lite. And that's what we're gonnacontinue using for this video. Most of thetimes when you're working with Python, youmight want to use Postgres, you may want toswitch was also very easy. We also talkedabout that. But for now, let's just stickwith the sequel light. So we want to changethis class into a real jungle model and Tonyto a database, we need to add some thingsright here. For example, where we have thisfixture, what we just need to do is to say,open the bracket, I say model dot model. Nowthis converts in this basic class into a model.And then whenever we're using this model,we don't need to add an ID again, becauseautomatically each attribute or each objectas an ID when it's created. So now we canremove this. So now when we have name, wecan change it to equals to. So now insteadof writing str, write something I'll say modelsdot current field. Now this model dot charfield simply means character field, it meanslike a string of food accolades characters,now we're gonna open a bracket, and it takesone attribute, the attribute is Max length.So this max length is five the maximum amountof characters that can be inside this characterfield. So for this name, we cannot specifyAndre it shouldn't be more than 100. And thendetails as you might have guessed, he shouldalso be a character field. And they are varioustype of fields a lot of fields in this junglemodule the integer field to Boolean field,they is their present a few ways you can use.So catch if you do so the max length, we canset it to 500 because the detail and thenfor did is true. I'm sure we don't need theseagain. So let's just have the name and thedetails right here. Now we can save this Nowthere's something we need to do before thiscan be saved into our database. For now, thisis just code in a file named models spy, weneed to send all these fields into our database,so it can be registered right there. But beforewe do that, this app, which we are doing allour project a, which is called my up, we needto register it in our main project settingsfile, went to come in here, go to settings.pi.And then we can scroll all the way up, I willlook for where we see installed apps righthere. And then we can just add a new attributeand say my and this is going to add this myapp into your main project. So you need toadd that before you can start integratingdatabases of this my app into your main projects.So now we need to migrate these data intoour database. Let's go back to our commandprompt, and they just open a new command prompt.And then we come here. And then they justgot the screw up. So right here, that shouldbe it, we screw up again. Yeah, so that shouldbe right here. And then we just go into that.So what want to do now is to type Python manage.pymake migrations. What this command line doesis that any changes in which you made in themodules file. So if I come back here, yousee that we made some changes right here isgonna like save that changes. And then asyou can see, it says we created a module namedfixture. So it's gonna save that changes.And they forgot to send all these changesinto our database, we need to migrate it bysaying Python manage.py migrate. So it's atwo step method. First of all need to makemigrations and migrate. So that make migrationswe need to do it. Any time we add or changeanything in these modules with pure alpha,they will come in now I removed this detailattributes, or let's say we add another attribute,we need to come in and do this two step again,my make migrations and migrate. So it canbe reflected in our database. As you can see,everything that migrated. We have contenttypes, out admin content types, authentication,all these, and then applying my up 01 inicia.So what this is, is all this module we havein here. So right now our database has beenmigrated. But I'm sure you like to where didour database go, basically. So we're justupon right now. We have something we callthe Django admin panel. So all these databees are being pushed, be moved into theseinto the SQL lite database. Why can we viewit and edit it and control it as we like thatwe are Django data, or Django admin panelcomes in. Now, obviously, we are using Postgresor using any other interface, you can justeasily use those interfaces because they aremore advanced. But because we are startingfrom the basics of Django, I would like tointroduce you to the Django admin py first.So if you come to your project now, and thenyou go to slash admin, so your project slashadmin, and you enter, you're gonna see what'sgonna happen, is gonna ask you to log in.So right here, you see says we should login, with what details we don't have any detailswe've never added, sign up and sign in, intoour project. But this is an admin site, itis not your normal site, again, it will gointo another part of that site. We're onlywe developers can get credentials to thisparticular site. And to do that, we're goingto come into our command prompt. And thenwe're gonna say python manage.py. Create superuser. Now this command line creates superuser. What it does is it creates an adminuser. So right here you see us for user name,I can say admin, and then it asks for emailaddress, I've asked him that, and then itasks for password. I can't say that again.So now these UCC supplies are created successfully,what I just input I can, does not be createdsuccessfully. And I can use these to log in.Yeah. So if I say admin, and I come here andjust input the password, and I enter, she'sgonna take me to an admin dashboard, as youcan see right here, right here, I can maintainand control my size, any hour, like, withouteven having an external database UI. So ifI come to this users, you're gonna see thatI'm going to see all the users I have in myproject. So right here, I only have one user,which is admin. And that is me, which wasthe user I created, right here in the commandline interface. So later, we are also goingto integrate our going to add sign in andsign up. So once these are registered, itwill be saved to this list, also going todo all those. But what we want to do now,we created this database name feature. Andas I told you, we migrated that into our database.But why aren't we seeing it here? Let me explain.So this admin panel, there's a file in ourproject, which is controlling the admin panel,if we come right here, you're gonna see wehave admin dot p y. So this file is really,we need to register our modules, because hesays register your modules here. So this ModuleDatabase, which we created, we need to importit here and register it in the admin, oncethat is done, is automatically going to reflecthere. So what I just need to do is to say,from does modules, import feature. And thennow I can just say, admin does, sides doesregister. And then this is just gonna savefeature. I was I saved these, like, come oneach refresh, you're gonna see now that Ihave a new database table new features. Andnow I have no database right there. So letme just create a new database a new data,let me see, quick, let me see, our productis very fast. And they let me just save it.So now that I've saved the, we have one newobject in our database. Now I can come here.Since I have one object in my database, Idon't need to use all these that I created.Again, all these right here. So now theseare old, we don't need all of these. Let meadd another object in my database and say,reliable. Say, we are very, very, very, veryreliable. I know I'm gonna eat safe. So nowI have two objects. Well, how can I get allthis data that I have right here in my views,or in my project. So what I need to make sureI'm doing First of all, is that I'm importingthat feature, a feature module. So this moduleright here, is linked to this database linked.So once I assess this feature in my code,automatically, I'm assessing all the valueswe have in this database. Now I'm gonna havea new file, I'm gonna have a new variable,I'm gonna name it fixture fixtures, and I'mgonna say fixture objects. So, I'm gonna explainwhat this means. So we have this new variable.And this new variable is getting from thisfixture that we imported. And it's sayingdot objects dot four. So this feature thatwe imported is this database. Now, each ofthe value we have in this database, each ofthe data is an object. So as you can see theseobjects one object to so it saved from thatfeature database gets all the objects we havehere, get every single thing as storage inthis variable. And now this variable is alist. And then right you are passing it tothe HTML. Let's come here. And then illegiblestatements because we don't have a booleanvalue again, we just have the name And didyou. So while looping through the data wehave here, let's go into our project and seewhat we're gonna get. So let's see. It saysfast, reliable, easy to use affordable. AndI'm sure this because we've not saved ourfile, so let's come here is safe. And thenlet's refresh and see what we're gonna get.Good. So as you can see, it says, quick operatesis very fast and reliable, we are very, very,very, very reliable. So there might be someerrors in the code, as you can see right here.And that would be because of the way we putit here, I'm very sure. But you can see thatthose two are shown. So they just have thecontrol Z here. So that was where we addeda problem. Let's save it. And once we hitrefresh, we should have that styling arrow.So you see, we have quick, we have reliable.So now you see where we linked from our databaseright here. And we linked it right here intoour project. So what I'm going to do now isthat I'm not even going to go to my code anymore,I'm just going to come right change my database,I'm going to add a new data. And now let mesay, a fully let me say, we very affordable.And then when I eat safe, noisy after objects,if I come and eat you fresh, you're gonnasee now that I have three objects, which isaffordable, and we are very affordable. Sowhat is my database is now what is reflectingyou, because of what I call it. So I hopeyou guys understand and enjoy what we've beendoing in this Django course. Because thisare the basics you need to know to get startedreally coding with Django. So now, let's continuewith some things. We've seen how to createour modules, we've seen, we've talked aboutthe admin panel, we've talked about how wecan add on fetch data from the database. Andthose are the most important things are goingto need anytime we're working with any projectsin Django. For now, let's use the if statement,just like we used before, but now we're gettingour data from here. So let's say if the nameis squeak, then we want to just add something,we can do anything. So I just want to showthis to you as an example. So right here,we can see. See, if the feature does dad'sname is equals to quick, then we can justsay, can never be and say this fixture sayssides is quick. And then we can end the ifstatements. Now let's save the outcome, youthen hit refresh. So as you can see righthere, it says this feature says our site isfree, because it says that the name is quick.So of course I'm sure it's because there isan error. So let's just do the best righthere. And then let's refresh it again. Andyou should be beneath this. So you can seethese features is our site is quick, becauseit gets that the name of this particular datais quick. So you can see that that is howit is easy and doable to manipulate your databaseusing Django. Now, this is very importantin Django, and I hope you understood whatwe've been doing so far on to this point.Now let's talk about user authentication inDjango. Now, when I say use authentication,what I mean is signing in as signing up toa platform, like when you go to facebook.com,and then you sign in to the platform you'rededicating to your account into that platform.So let's add that fixture in this our project.The first thing we want to do is to allowa user to be able to register into our site.Now this can come with a bit of complexity,but just follow me along as we do this. Sothe first thing we want to do is to Have anew URL, which will be named register. Sowe're gonna have a new URL right here. Thenit should be views, loads register. And thenlet's give it a name of register. So we cansave that. And then second thing we want tohave is in the views. So first of all, wecan get rid of these on these on these. Solet's have a new function. And limit register.lets you just take your request for no lessreturn render request, register dot html.So for now, we don't have registered withHTML. So let's create that real quick. Andthen right here, we just create a new filename is registered HTML. So right here inthis register that HTML wants to have a simpleform. So see, sign both below. Now, we'regoing to use the form tag on this shouldn'tmean like an h1 right here in the form tag,we want this form to be a post. So same methodshould be posed earlier. In this tutorial,I talked about why we're going to use supposefor this kind of form, and then the actionshould still be this register. So I want youto come back to this page. And then we'regoing to have an input. The type shouldn'tbe text. And then let's give it a name ofuser name. And then let's close it. Beforewe close it, let's give it a bit. So let'ssee user name. And then we can just add anotherone for the email. So right here, we can sayemail. And any type of this one should bean email. And then the name should be email.So if we go to slash register, so you cansee user name, email, and then let's havefor the password, so this should be passwords,the first password, and the type should bepassword. And the name should also be password.And then this should be repeated password.And the type should be a password. And thename should be like password to finally haveone more thing, which would be the input forthe Submit. button. So this is a Brb, so itshould look good. Now let's hit refresh. Andas you can see, we have the user name, email,password, repeat password as Submit. So wefill this in an installment now, nothing isgonna happen. So they say, just a team. Andthen as you go, live your random passwordsand random tweets, I mean, nothing's gonnahappen. But it gives us this error and saysCSRF verification field. So the reason whyit's given us this era, as I explained earlier,is because why isn't a POST method, and thenwe didn't add the CSRF token. First, comeup and add a route Quique to CSRF underscoretoken, we save it. So now we have that done.What we want to do now is that right herein these views, we want to be able to collectthese, all this data. And then that is gonnabe quite easy. So what we can just do is righthere can just see the user name should beequals to request dot bulls And then username.So what this line of code does is that whateverwe're posting into this register view, wewant to get it as storage in a variable namedusername. So we're going to do the same thingfor the email. And then you get the email,the password, the password, and then passwordto get it as password to. So now that we haveall these details that we need, what we canjust do is to save all these details intoour database. And the database we're savingit in is this database right here, users,this database, so this database is for theusers active on our platform. So let's goback. And now we get these. So what we canjust do is to just simply say, first of all,before we get all these, we want to checkif requests, the method is equals to post.So we're checking if there is a POST methodbeing like if this if this page is being renderedwith a POST method, they want to get all thesedummies something is being sent to this view.But if this doesn't happen damage, a useris just looking for the normal registeredwith HTML template. So if his post metal damagethe user as filled in the details and clickedon submit, and then is waiting to be signedup. So what we can just do now is to justsee, firstly, we want to make sure is thatthis first word is equivalent to this puzzle,we want to make sure that they are the same,they are equal. So we can do that by seeingif password is equals to password two. Soif password is equals to password today, wecan continue with what we want to do. Andthen before we continue now, there are somethings we need to import. And then what weneed to import is, we're just going to scrolldown for over a year we need to import redirectis redirect is going to allow us to say we'vecreated a user successfully, I want to takethe user to another page, it will allow usto redirect the user to another page. Andthen want to say from Django dot country,the report dot models import user on both.So this user is this basically this user modela senior and then auth is the function arethe methods that allow us to dedicate. Soanother thing I want to import is messages.So from Django, does country input messages.And I'm going to show you why we need ourmessages later. So now that we have all these,we can continue with our authentication. Sowe said if password equals to password toso even the user, that means right here ifOkay, I know why this is happening. So becausewe are just using a request. That's cool.So first of all, let's save this. Let it refresh.Let's see. So this is for server to run backup. So we didn't use the column right here.After these, we should use our column. Andthen let's see. Okay, so let's quickly fixthis before we continue. What we can justdo now is to first of all, got to this, ofthis, like this. So now when we save these,and they will come here. Let's see now itdoes work. Okay, that works. So we can callme on it, refresh. So we have this running.Let's come back and continue. So now we arechecking if If password is equals to passwordto so if this first word is equals to this,it must be equal, then we can continue withour signing up process, then want to checkif this email already exists because a usermight use an email that already exists inour platform, we want to check if the emailthe user is providing already exists or not.So right now, we can just say if user dotobject dot filter, email, because email doesexist. So this is gonna check you the emailalready exists. So if it exists, want to throwan error and say messages. Does info requestemail already used. So what I just did herewas I said if use that or talk to the future,so this user is this user model, which weimported earlier on. And I said that is ourmodel is this user database to say I wantto filter the database unchecked, if thereis an email, which already exists with thisemail that the user just submitted. So ifthat already exists, want to send a message.So this message was, Remember when I saidI'm going to tell you what this message isfor. So that is what is for is used to senda response back if there's an error or anything.So since there's an arrow, which is that theemail is ready in USD, so we say messagesor info requests email already used. So I'mgoing to show you how to show all these messagesin your template right here. So if there isany message you already used, is it goingto show up over here in like a red color orsomething, I'm also going to show you howto do that. So right here, now we say emailalready in use. And then we now want to returnthe user names, we don't want to continuewith the signup process since the email isalready used. So redirect the user back toregister. So what I just did, after sendingtelling the user what happened, we just redirectthe user back to register with just detailsright here. So the user has to go throughthat form again, and use another email leave.So want to use another condition. And whatwe just want to do is to check if the username also exists, because it is almost nonexistent the email and the user name, we mightlook at, we cannot have one account with twoemails or one account when to use our names.It just doesn't make sense to because theleaf user objects dot filter, and then username equals to user name that exists justexactly what I did. Didn't even oppose justsay messages, that's info. And then we'llsay request. on there we can see user namealready used. And after that want to returnthe user to the register. Turn reader rich.Now after doing this, what we just want todo now is so if password is equals to passwordto then want to continue with the signup process,and then if you don't object or future dotz is show the user this error. Or if the username is existing showing this error. Elsethat means if any of these is false, we justwant to do is to create the user. So if anyof this is false, that means the user nameis brand new, and the email is brand new.And the password is correct. The initialscreated our user. So we can see user cannotbe equals to the user. Objects not createuser. Now we can say create user in whichthe user name is equals to the user name Thenemail, it goes to email. And then passwordis it goes to a password. So what I just didknow was, I said it should create a new userwith these credentials. So these are the credentialsin this credential. So when the user nameequals to this user name, the email equalsto this email and the password, I just pickedone from this one of these two passwords,since they are the same thing. So I just thinkthe first one. So now that we have all thosedetails, what I just want to do is to go aheadand save that user. So the user does savethe code. Then after doing this, I just wantto redirect the user. All First of all, tothe login. So since the user can guess beencreated successfully, unless redirect theuser to the login, so the user can try tolog in and see if the E was created successfully.So we use the if statement, if the passwordis equals to this, and then you should justgo ahead and do this. But what if the passwordis false, like if they are not equal, theywill need to have an else statement that saysthose password is false, they send a messageI say messages dot info, requests, and thenreceived buzz words, not the same. And thenwe just redirect the user back to the register.So after that, we can just say, after everythingis also loaded these so if it's not a request,the method is not post and you just get, itcan just do these. So let's see right here,we can see else like this. So it is just anormal request on this page, he can just renderthis registered with HTML. But now what wewant to do is I want to show all those messages,if there is any error, see these messages,we need to show it right here if any erroroccurs. So first, to show these messages weneed to do is very easy, we just come up hereand say we'll use a for loop. We'll say formessage a messages, like an H five, that justshowcase the message. So whatever messagesthey just shut cases, and unless they endedthe folio. So and for now, let's just do themessages, a simple styling, so we can seethis. And then let's give h5 color of therich. That's to show a warning. So now allthese is working. What I just want to do isto come here. First of all, since I know Ihave a user name with admin, I'm going totry to register with admin. And then let'ssay admin@gmail.com. I'm just going to usea random was. Now you'll see it says usernamealready used does because we already havea domain user right here, it automaticallygets that this user name has been used andit tells us user name already use it. We'lldo the same for the gym, you get right nowwe don't have any Gmail, but we can come tothis admin user. And then let's see if wecan add this admin user ID via an email. Today'sgiven an email, say admin@gmail.com. And thenlet's just see, try to save it. So now hedoes admin@gmail.com. So let's copy this now,let's try To use that email, well, let's usea random username, random password. We enternow what it says is your email already used.So it gets all those arrows on them. For usit was. So what I want to do now is let'suse a brand new information so we can seetheme. And then we can see theme geo.com.It should be under let's say, just give mesome password. Enter. So it says reverse forlogin, not fun, I was expecting this error.So the user, the person has been created successfully.If I come here and eat refresh, you see nowthat I have seen this email address on everythingwe need. But the reason why is because ofline 29, where we say return redirect login,let's quickly go back and see what was goingon. So in line 29, after saving the user,after creating the new user will redirectthe user to log in. But we don't have anylogin function for now. I wanted us to beable to log in. So we need to do that next.So now to this point, we've been able to createa new user, let me just register a user onour platform. And what wants to do now isto be able to allow the user to log into ourplatform. So when we created a new user, andwe tested our code, we saw that the user wassuccessfully created right here in our database,which is Tim, but it gives us an error, whichsays return redirect login. So this erroris because we don't have any URL named loginfor now. So let's go ahead and fix that we'regoing to create a new URL for the login, ourgonna allow a user to log into the site, thenwhen a user logs into the sites, instead ofjust showing all these dummy or starting data.Let me quickly open our site. So quick, quick,quick. So instead of showing like one pageor so it can just say welcome team, or welcomeadmin or whoever the user is, we can do that.So let's go ahead and do this. So right here,what we just need to do is to make sure tobecome into urls.pi, we need to create a newURL named path. Then is given login viewsdot register. Now view the login. And thenthe name should be login. So now that we havethis URL, we need to create a function namedlogin. So right here, right below the registerfunction. Let's create a new function forthe login. Take a quiz and then press pausefor now. No, no, no, let's return render requestand then login dot html. So let's copy theseand this should be your login. So let's savethat. Right here. Let's create a new filename login dot html. Right in here, there'san h1, which is looping now. I'm below itloads of form. And then this form wanted theaction to be login and the method to be post.So now there's a p tag that says username.And then an input like wasted type of textand the name of the user name. And then there'sanother one just for the passwordand then input type, password and then Giveit a name of password. And then the last one,we're gonna have just have a break right here.And then another input for the Submit. Sotypes of meat Are we safe. So now we havethis page, go to the login now, you see nowthat we have this login page. So let's fixthis login, let's make a user really be ableto log in. So what we just need to do justwhat we did in the views for the register,we can just do for the login also offers andget is a POST method to say if request dotmethod is equals to post is a POST methodthat was to get the user name which was sentshouldn't be request dot posts. And then username and then the password which was sentalso. We shouldn't be request this boostspassword. So now that we have these two, informationsaved in the variables, what we can just dois to say user attribute equals to us thatauthenticate user name shouldn't be equalsto user name. Password should be equals topass rush. So now wants to enter educate withthese details. Now we want to log the userwith these details. But before we go aheadand do this, what if the user provides wronginformation, which is not on our database?So we want to check for that want to checkif the user is really registered or not. Sowe'll see if user is not known. So this ishow to check. So what do you see that is useris not known. If user is known. That meansthe user is fake. That means the user is noton our platform, but it is not known. Nowas the user is really on our platform is registered.So we can say dot login, so that we know theuser is real. And their request user afterlogin design, we can now redirect the userto the home page. But what if the user isnot registered, so want to send the messages,messages and the messages receive messagesthe info quiz that will say credentials invalid.And then what to redirect the user back tothis page. So return redirect back to thelogin. Page, those who have else. Good. Nowwe've done all these. And then what we justwant to do is to come into our login and alsoour messages. So we use a for loop I say formessage in messages. There's an h3 sayingthe message under less than the full loop.So they just give you the simple style again.They will say h3 should have a color of red.Okay, red. So now, let's just test this out.We can come here in our page, hit refresh,and then let's login as the admin so we cansee admin, and then we log in. So it givesus this arrow and as I said, just erased becausewe didn't add our CSRF token. So let's goahead and add that right now. So right here,just say, percentage sign CSRF underscoretoken, in small letters. Now receiving doeswe eat refresh? No, this mean. And then let'ssay Submit. You see now that it redirectsme to this page to the home page, that meanswe're logged in successfully. But now forme to really know, what I'm gonna do is insteadof one page bootstrap, I'm gonna say welcomewhatever the user name is. So let's do that.Right here in index. Default, where we seeone page bootstrap. So we have get started.Ah, yeah, right here. Again, no, no, no, thisshould be easier. So let's just add a P andsee if that is what we're looking for. Again,know that this is it right here. So there'sno age, so isn't the one with space. So thisis just right here. So let's quit this. Sowe can do now we guys an if statement andsay, user that is underscore often seek ated.So this is checking if the user is loggedin. And then if the user is logged in, insteadof showing one page bootstrap, we just wantto show welcome. And then we'll say welcomethe user. username, associate user, dot username.So this will get the current user that isloading and get it user name, sorry to say,welcome admin. But what if the user is notlogged in what the visuals are random guestuser visiting, then want to have another statement.So then, we just ended up for end use statement.And if now let's go check this. With refresh,we should see welcome admin. So as you cansee, now it says, Welcome Academy. But nowlet me just copy this URL, and then open likean incognito tab, or private window whereno user is logged in, you will not see thatthat will be different. So what's going tobe written here will be different. So thatis where we're not talking more about dynamicvalues, the same page, the same code, thesame everything, but different output. Sonow I see says one page bootstrap, where itsays welcome admin, if it seemed that is logginginto, say, welcome, Tim, it was john, it willsay welcome, john. So that's how you can dosimple stuffs like that. And then let's goback to our code. So right here, we've seenhow to do this, we can also do the same thingfor you, we will see all services. If theuser is not logged in, like if the user isjust here, we can change all this to log insign up. And then once a user is logged in,we continue to log out. So we've talked abouthow he can register on our platform. We'vetalked about how he can log in on our platform.But we have not talked about this, our usercan log out. So we need to add a lot of functionality.So you don't always talk in our platform,or just be trying to clear cookies and timethe user wants to log out. So we just wantto have like button year where do you sayget started and actually log out once we clickon it. So this is the easiest thing to doin this tutorial. Now we're just gonna searchfor your CDs get started. Getting this isit right here. So you know that's not justsearch you Okay, so this is it right here.Since we already know where it is, what wewant to do is use that if statement again,and see that if the user is logged in, thenwhat want to show the is logos where the useris not logged in, what want to show do islogin. So let's see. If If user that is underscoreauthenticated, means users logged in, I wantto show feature for a user to log out. Andthen this, I'm going to leave him blank fornow. I'm going to come back when I've donethe URL and the views for the logout. I'mgoing to come back and change us. But whatdo you do user is not logged in, so therewill be an else there, what I just want toshow is this same thing, but what I want toshow now is login or signup. So now let'scheck this ad right here. I'm logged in. SoI hit refresh. It says our close tag, if sothe reason why this give us an error is becauseas I said, we need to end the if statementwhenever we're finished. So and if they willcome in each refresh again. Since we're loggedin on this browser, we should see log outs.Good. When we come to the incognito wherewe are not logged in, we should see loginor signup. Good. So now the same button, butdifferent texts. This is what I've been talkingabout when I say dynamic when I say somethingis dynamic. So now let's take care of thislogin of this log out. First of all, thislogin should be easy, I can just redirectthe user to log in. So I mean, come on isrefresh. So if a user is not logged in, Ican click here and take us out to the login.And at council are like a bottom below, I'llsay if you are not logged in this, if youdo have an account, then create one by signingup. Now accounts will do that. So what wantsto do is log out. Now let's do that we canjust do is to come into VS code. And thenlet our new URL path log out. Views does logout. Me name equals to blog outs. And thenin the views right here, you can just haveto log out which take your request. Over there,what I just want to do is to see what doeslook out requests. So this single line ofcode will log the user out of our platform.And then once the user has been logged outof the platform not to read put on and redirectthe user back to the home page. So now let'scheck this out. Well before we can check itout, we need to come to our index. And theyright here in the logout, we need to linkit to log out. Good. So we come here now onit refresh. So once we log out, it will redirectme back to this page. But now it doesn't showwelcome admin and he is login or signup. Sothat's how to do the basic user authenticationin Django. I hope you got on and as to whatwe did, up to this point. So now we're goingto be looking at dynamic URLs in Django, towhat I mean by dynamic URLs is to for example,we have the same URL but with different IDpassed in it. So let me just quickly explainthis practically. Let's say we have this ourwebsite slash Tommy taco. So our website slashTommy and then this is the File page one isgoing to give us an error because we don'thave anything like that. But let's and thisis the profile page for this user named Tommy.And then we also have user name team. Andthen we also have for a user named john. Solet's say we have for every user on our website,they have each profile page. So for us togo, this is just going to be one page, weare going to code. But because it is gettingdifferent user name, it is going to be differentoutputs. So that is dynamic URL routing, differentURL being passed, or different values beingpassed in the URL. Now, let me explain thismore practically. So let's come right here.And then, you know, URLs, you know, up, closethis up. All right here, we can do somethinglike pass, then we can see something like,posts slash str, big K, and then we closeit. So what this means is that we're havingslash posts or website slash posts, then slashstrings. And we are naming the string DK.So it's just like a variable. So the variableis named BK and is a string, if we want itto be an integer, we can just say, both, Ilike sticking with string. So now we can justadd a comma and say, views, posts. And thenwe can give it a name of posts. So now first,to be able to collect this in our views, weneed to come here now. And then scroll allthe way to the bottom. Another new view, Isay, posts, service shaky vs post return s,so posts, and you're gonna take a request.And after this view, taking a request is alsogoing to take that particular variable whichhas been passed, which is called PJ. And thennow what we just want to do is to say, sowe have this PK, and then Kathy return renderrequest, and the list goes does HTML. So there'sa script a new file, named pose dot html.Now let's send whatever value is in that URLto this post HTML. So we can see BK shouldbe close to p gay. Now let's save this. Righthere you see the value in the URL is BK. Nowlet's save this to become your now I'll sayslash posts, slash 12. So now you see it saysthe value in the URL is 12. Today just makethese h1. So now you see says value in theURL is to have. So whatever is in this URLis like Tim, the value in this URL is Tim.So is dynamic, whatever we pass in the URL.This is what is used in most sites, like whenyou have a profile page, which is like john,and then you see the name of the pressingjohn, then like, says, we have the usernameadipiscing, became the username to the topinto the database, I get the profile picture,get the age, get all the posts, get everythingwe need about a specific user. So is stillone same template file, one same code, butdifferent outputs relating to what has beenpassed, or query to form in the URL. So thatis what we mean by dynamic URLs. Now, we canalso make this more add some more featureslike right here, in the URLs. We can haveour integer here. So now this is an integer.If we come here, and then we hit refresh,you're gonna see dices page not found. WhyWhy did this happen? This is simply becausewe write in our code, we say we want onlyan integer right here. So if anything, apartfrom an integer is being Pass in the URL,if you see it or not found, so it's not partof our code is not part of our project, wherebychange is now 298. And it enter, you see nowit says the value here is 98. That is becauseit sees what we told it to ask for, it seeswhat we told you to look for. So that's thesame thing we can do with any type any, anydata type. But the good thing with string,what I like using string is because I canput in an integer in a string, and it goes,it's gonna see it as a string, even if I meanit as an integer. So most of the times youwant to use strange because it helps you avoidplaying the arrows. So you don't want to useinteger there. And then someone queries yourside and say same. And then let's go for changesto an integer and say team, and the Presidentcomes to your site and then sees these arrows.Of course, this is not developed by just auser that wants to use your site. Even ifyou set debug to false, the best, he stilldoesn't want to see an error. So most of thetimes my personal devices, when you are usingyour dynamic you are set, you are very, very,very specific about it, I will advise youto use the string in it. So we can also dosomething like making this more usable. Solet's change this to string back. And thenright here. So you know, this in our counter,just remove all this. So let's have a post,which is equals to 12345. Then there's john,yeah, that's fine. And then we're passingthisto counter dot html. So we'll pass it righthere. So now in counter, where I can justdo is to have a for loop. So now I can lookthrough that post, I can see for post in postson there, let me end the follow. What I canjust do now is to have a link tag. So in thish1, I can have a link tag I say. Let me givehim blank for now. And then what I can justsee his posts. So right here, for me to whatI want to do is, let me come to the counter.So I'll go and go to slash counter. So youcan see that I have 12345678. So correlatingto the amount I add in this list around todo is that once a user clicks on the firstone, it should go to slash post slash one.And then if you click on like this team, youshould go to slash Brewster's team. So ifyou know how to do this, then you know howto query it from the database when you justdo object dojo, and then get everything youneed. Let's just do that quickly. So now,what I just want to do is to say, the percentagesign and close that, and then I'm just gonnasay URL. posts. And then was the ID buzz?No, just first. Yes. So like this, on thewinner, eat refresh. They're gonna see thatthe first one is eat one, eat. The last oneis john. Which right here is john. If I goback, and I eat this, you see steam, if Igo back in our indies you see is four. Sothat's how to get from like a list and thenturn it into a URL. So this simple triggerthis demo feature I taught you, it can beused also when you are getting some valuesfrom the database. And then you can just turnthose into the URL. So let's say for example,you have a blog. And each of these standsas blog posts from your database right here.So the same blog one was either click on it,you should be able to read all the posts ofthe phrase blog, blog to read all the postsalso blog three, and so on. so far. So nowI hope you understood what we did in thispart. So what I want to do now is walk youthrough the steps of how you can connect anotherdatabase provider into your Django project.So throughout this project, we were usingSQL lite, which was provided by default forus by Django. So I said there are other oneslike Postgres for our cu, MySQL, dm two onso many that you can even think of. For thisvideo, I'm going to be showing you how toconnect Postgres database into your Djangoproject. So the first thing you want to dois to go to search engine and just downloadPostgres so what you want to type is downloadPostgres. So this is going to take you todecide whether you'd be able to download Postgresobviously. So, yes, this one, Postgres doesBoggs slash download, and then it takes youthere. You see different versions, and thendifferent years for different OS. So justclick on yours. I'm on Windows, so I alreadyhave Postgres installed. So I'm not goingto town to these. But if you're on Linux,click on decks. If you're on a Mac, clickon this windows, Solaris, BSD. And then thenext thing want to download is PG admin. Actually,recently, once you download Postgres PG adminautomatically comes with you. But if you downloadPostgres and install it, and you don't seePG admin, then just come here and downloadPG admin, and just download the one for us.So once you have all those downloaded andinstalled, you can just open up your PG admin.So once you open up your PG admin, this iswhat you are going to see. So now, what youwant to do is to open up this server likethis, and then under Postgres SQL, open updatabase. Now, if you want to create a newdatabase, just right click on this databaseand eat, create, and then click on database.So now this is going to bring a form for youto create a new database. So we can add adatabase, my project. And let's save it, that'sgonna create a new database for us. So thatshould save all this are saved are createdour database, I'm going to show you how toconnect that database into your Django projectvery easy enough. So this should create. Giveit a couple of seconds. Sure, let's see. Thisshouldn't take this long. But most of thetimes sometimes PG admin usually lags or comesthrough did to your system. So see, okay,good. So that has created we can close thisone up and open that. Now that we have theseopened, we know that the name is my projects,where we can just do is open schemas. Andthen open up tables. So as you can see thetables is empty. What we can do now is tocome into VS code. And they want to go intosettings just pure to open up our projectfolder, and then go into settings spy. Sorise, down below aregoing to go to go We'll see database. So righthere where we see database, what we just wantto do doesn't default was a change from engine.So we can see is Django DB dot backends dotSQL lite three want to change that to PostgreSQL.So plan this, and then the name should bethe name of the database. So we know thatthe name of the database is my project. Soright here, I just want to have my project.And then the next thing that should be clearis the user And the user is Postgres, so justuse us us Postgres. And then after that isthe password. So the password which you setwhen you first created when you first openup the PG admin is what should be in here.So I'm going to leave that blank for now.And then the boost for now is the localhost.So we have all these. And then once you haveall these in here, the next thing you needto do is to open up your command prompt. Andthen right in your command prompt, you needto install two libraries, and the sidecarto specifically be installed. Cycle two. Andthen after installing cycle two, I alreadyhave that installed, so I'm just going tobring the out of it. So I'm breaking out ofit. And then I'll say FP install pillow. Sothese two libraries are gonna allow you tobe able to connect Postgres to your Djangoproject. Without these libraries, you're goingto receive an error. So this pillow takescare of everything. Let's say you have a databasethat deals with images or files, this pillowtakes care of it asac have to connect themtogether. So because this requirement alreadysatisfied, I already have that installed.So once you have this setup, and you havethis installed, we'll just need to do is justPython menage does poi make migrations. Sobefore I say make migrations, let me go intomy code and input my password. So they'reright here, there's gonna see make migrations.And this see the migrations to make. So let'sgive it a couple of seconds. Oh, that shouldn'ttake time. So was this big migrations is justgonna suppose just cannot change detected.So by turn, manage. Those few are migratesoon, is performing all migrations for thistime, taking into Postgres. So now we willcome back to Postgres on the on this tableis now right click on it refresh, you're gonnasee that we now have a bunch of tables, evenwith that model, which we created my app underscorefixture. So if I just drag this down, andI say view, data, all rules. So I'm goingto view all the data I have in that mom fixturesmodel under my app. So let's wait for thatto come off. And let's see. So this shouldn'ttake a while. She just take a couple of seconds.And it shows all the data base, which we'vesaved from our admin panel earlier on. issuewas right here, because we migrated everythinghere. It should be the database it shouldstart using from now on. So you can do thesame for MySQL or Roku, as I mentioned, they'realso similar processes. And I'm very sureyou might find it cool and more helpful touse some external database provided and justusing the default SQL Lite. So right now,this is it. And the data output we do nothave anything right here. But now if we uselike if we create a new one now it shouldshow right here. So this is how to connectPostgres to your Django project. Now, I hopeyou understood everything indeed in this video.And yeah, so now I hope you know how to connectthe Postgres database to your Django project.So guys, that's gonna be all for this video.I hope you enjoyed this. Oh, course. If indeed,please don't forget to smash the like buttonand subscribe. Hey, what's up, guys, welcometo this video. In this video, we're gonnabe building a simple blog using Django. Sothis video is gonna be in two parts. The firstbatch, we're gonna do everything we need toconfigure the blog. And then we're gonna startwith the posting of a blog, and then showingall the blog posts. And in the next part,we're gonna have some more features, likegetting only some particular words of theposts, right here, and then allowing the userto click on the post and read your posts.So I hope you're gonna enjoy building thiswith me. And then let me show you a quickdemo of what we're gonna build. So right here,I have this post, I can click on this postto read everything right there. And then it'sgonna tell me the day and the time and thetitle and the posts are very busy blog cando the same for any other one. And then let'squickly read the last one. So now all theseare being getting from the database. Now ifI come here and add a new post, let's justadd some rubbish there. And it's safe. Nowthat is saved coming, I need to refresh. Sothat is automatically updated here. Now, thisis what we're going to be building in thisvideo. And then this template we're usingis a very basic template. As you can see,I'm also going to have the link to this templateand the whole source code of everything we'regoing to be building in the description below.So you can have that if you want to checkit or anything to do with it. I'm going toleave it in the description below. And havingthat said, I think we should just dive straightinto this video. So guys, the first thingI want to do is to create a new Django project.So right here in this folder, I have thisindex dot HTML file. Now this is the fileto the template we're going to be using forthis blog. So I already have this templatedone to, we're just going to be talking aboutmostly the back end functionalities. So I'mjust going to import this template into myprojects. But first of all, I need to createmy project. So in this folder, I'm going tocreate my project. So now I just copied thisdirectory and come into the terminal Mr. VScode, right up inside that directory. Andthen I can just Okay, so let's open up thenormal terminal, to go into the photo sourcesCD. And then now we can see Django, I thinkadmin start project. And then we can say blog.So now this is gonna create a new projectin this folder, named blog. So in a second,it should do that. So that is done. If I comehere, now I can see plug. And then in therealso, I'm also going to create, I'm goingto go in the CD blog, I'm going to say pythonmanage.py. Start Up Alemany posts. So I'mgoing to start a new app and image posts.So done. Now if I come into the blog, I'mgonna see a new photo. So named posts. SoI'm done with this Tommy now I don't needanything yet again. So I'm going to closethat up. And then now what I just want todo is to open up let me close this terminal.I'm just CLS and then I can make this short.And close it up. And now I just want to openedup project I just created in my VS code. SoI'm going to open folder and then so it shouldbe in. Okay, right here. blog. Yeah. So blogand post. So I'm gonna select folder. Justgonna open that up. Yeah, and good. So now,there's gonna quit this. And then I'm goingto come into the folder. And I'm gonna dragthis index at HTML, I want to drag it intothe folder. So now I have everything in you.I don't need any other thing from the folder.So right here, I'm gonna start all the thingsI need. So first of all, let's run this ourprojects are made sure that everything isworking fine. So right in here, I'm goingto save advice on one niche that's boi Ron'sserver. Now this you run our project on thelocalhost 8000. Okay, now let me come intomy browser. And then go on as you see thedefault Django template. As you can see, itsays install work successfully. So let's headback over closer. And now let's just startwith the URL mapping. So I'm gonna come intoposts, and then I'm going to create a newfile, name it urls.pi. Right in here, I'mgoing to set up all my URLs. Now, if you don'tknow what a Django URL is, is basically thedifferent path you have in your website. Let'stake example facebook.com. So facebook.comis the main website. Then when you go to facebook.com,slash notifications, there's another URL,go to facebook.com, slash messages, there'sanother URL. So think about that in this project.So URLs is different spots in our website.So now, let me show you how to configure aURL. So I'll say from Django dot URLs, importpath. So this is just a default Django functionthat allows us to, you know, configure URLs.So I'm going to see URL patterns. Again, there'llbe a list, and I'm going to save path. Andwhen I leave him blank like this, it meansthe home URL. Now if I put something likenotifications, what this mean is slash notificationor website slash notification. When I leavehim blank, it means the own URL. So now Ican say views dot index, and I can give ita name of index. So this is saying that oncea user comes to the home, it should go tothe views dot index function. So that meansin this views.py file, it should look foran index function and then do whatever wasbeing asked to do. As we can see, we don'thave any index function a view, we're gonnahave to create that. First of all, we don'thave views imported. So we have to say, fromviews from this import views. So now we haveto use a button, we can say view dot index,and then we just give it a name of index.Now that's it. And then right here, let'screate a new function and name it index. That'sgoing to take your requests. Now we want thisto render that simple HTML page. But beforewe do that, if we just type return, renderthis out to render an HTML page, and we dorequests index dot HTML, if we do this, wearen't going to see this is either going togive us an error or is going to show us theDjango default template. Now for us to forDjango, to know where to get this interpretation,we need to do it in a specific way. So inthe root directory, we're gonna have to createa new folder and name it templates. And thenwe push index dot HTML into template, so wantto move it. Now it is inside templates, thisis how it's supposed to be. But we're notdone, we need to come to blog and go to settings.py.So right here in settings, or to pure Whyare gonna scroll down to dares are gonna seethis deer slash templates. Now, what thisis saying is that whenever a user requiresan index, an HTML page, it should go to thebase directory, which is the root directory,then it should go into the folder named templates,and look for that exact HTML page. So whenwe're trying to render this HTML page index,HTML, is going to request for this index dotHTML in the root directory. And then it'sgoing to look for a template name, a foldername templates, and then gets done index dotHTML. So now we have this. But again, letme scroll up to installed apps. And I haveto add this app I created which is posts,you have to add it there. So now I can savethis. And now this can be rendered. So I cansave this also and save this. But if I comehere and eat, refresh, boom, nothing stillhappens. And this is because we configuredall this in our app, we need to configureit for our main project. So project we knowwhere to look for a URL. Now, for us to dothis, I'm gonna say from Django dot URLs importpath, you also have to import include Andthen we can see the path when you use theboom is gonna include was dot URL. Now whatthis is saying is that once a user comes tothe home, which is just the main website,it should include the own URL in posts thatyou are opposed to Yara is our app dot URLs,which is this. So it's going to look for somethingsimilar to this, and this is it. So we canclose this up. Now we come here to refresh,boom, you can see now that we have this HTMLpage, we have a written set of whoever thefront end set up. Now, I guess it's time forus to do the main stuffs. So now, what weneed to do is to create a database that isgoing to store all our blog posts. So it'sgoing to store the title of the blog post,when the blog post was created. And then themain body the main text of the blog post.So we're going to come into modules, whichare gonna create a new Django model, let'ssay class. And then let's see posts. So Iwill say models dot model. And now we cansee, the try to shouldn't be equals two models,dot character feud. And then we have to seta max length. Let's set the title should belike 100 shouldn't be more than 100. And thenwe have to do the same thing for the body,which is the main posts. The body of the postwas also models towards character field. Andthen the max length. Because says, like, let'ssay, a million, because some blog posts mightbe who. And now, the next thing we need toset is the dates this post was created. Sowe can name it created, underscore art. Unknownas models, dot date, time field. And thenfor us to pass in a parameter we need to importdate, time is a default fight on libraries,you can see from date, time, import date,time, basically, date time. So now we canjust pass this date time in years. So wheneverthis is created, this is going to be savedwith it, we're going to get the current dateand save it with the source in defaults. defaultsshould be equals to the date time.no. On thenose leave blank to be true. So now this isgood, we can save this. Now we have our modulesdone. And you know, in Django, one ever youcreate a new module or you add any changesto your Moodle, you need to make migrationsand migrate to the database. So let me createa new seminar right here. And then all I'mjust gonna do is make migrations and migrate,which is python managed.py. Make migrations.Okay. Make migrations. Yeah, it's updateddata on then python manage.py. migrate. Sothis should migrate everything to the database.Good. So now, as you know, Django has on defaultadmin panel, which allows you to access allyour database and everything about your site.To access that we can see our local slashadmin. But you see, it asks us for a loginusername and password, but we don't have debt.So what we need to do is to just come intoour terminal and say Python manage.py, createsuper user. So this is going to create a superuser. So we can have our credentials to login here. So we can see i'd mean, no, thisis just the username. So say admin, let'sleave the email blank and then give it a password.Then you So now we have this greatest sucessfully,we can use credentials to log in. Yeah. Sonow we have this, we have our database. Thisis the users we have on our site, we didn'tadd authentication or anything complex, we'rekeeping this very simple. The only user weare with us, which is the admin. So let mejust go back to the home, where we createdthis database of posts, then why isn't ithere? Now, we migrated this model to our database,but we didn't save it or showcase it in ouradmin partner. To do these are going to haveto come to admin.py. First of all, importor say, from dot models, import posts. Sowe have this model imported. And then we'regonna say admin, dot site, dot register. Onthe watch, I was gonna register that posts.When I come here, I need to refresh. Boom,now we see posts, as easy as that. So nowwe have this database, which is very good.Let's just go ahead and create a new post.And then let's say, tied to pleasure, say,out to deployDjango project to Iraq. So for the body, Iwant to have this report. So I'm just gonnago to my website collects the blog posts fromthe otter deploy Django project. And thenthere's gonna copy all of these, basically,I'm just copied to this place again. And thenjust going to paste it right there. And thenthe date is automatically going to get thelatest date the correct time. So I'll savethis. Now we have the first one. Okay, wedon't need this. We do not need all these.Yes. These posts. So let's just save this.So we got that. Let's just create anotherone. What do I have here. So best way to getstarted with Django sculpted is based on then.Oh, my gosh. Good. Copy. Paste unsafe. Sowe have to let's add one more. So we can usethe database and showcase it right here. Sogo back, get one more, let me say installationof bytes. Okay, that piece paste. And then,yeah, right here. And then we also paste thisand then good. Now we're good to go. So nowwe have three posts, Raftery blog post onthis our blog. And now we just want to assesseverything right here, instead of just havingno dummy data. And what we want to do is Iwant to use a CLI. So in this site to addin is obviously going to be the title of thepost, like how to deploy a Django project.And this is going to be the date. And thisis going to be just like maybe the first lineof the main blog posts. So once a user clickson these, they're gonna take the user to readthe whole post. Let's go ahead and do that.So now we got this. We don't need this again.No, we don't need this again. Yeah, so nowwhat we just need to do, right here, we canopen up our index of HTML, we're gonna needthat. So we're gonna make this dynamic ordispose dynamic recognizes static posts thereis there which is just this, we're gonna getall these from our database soon we're writingthese. So to dad's face after import thatour Moodle say from dot models import post.So now we have posts imported we can assessall the data or all the objects in that post.So we can just say posts should be equalsto boasts objects dot all and then we canjust pass it right here on sipos. And thensave posts. Now they should be a variablesuppose. So in this particular line is wehave a variable and we are giving it posts,which is this we imported dot objects dotall that means we're getting all the objectsfrom this database right here you can seethis object one object to object three. SoI get in all the objects saving it here, andthen we're passing it into our template, whichis index dot HTML. So we can see this year.And now when we come here, we can simply removethis, we don't need this. So now we're gonnause a for loop from year, so we're gonna usea for loop to assess for those data. So we'regonna see for posts in posts, so for postin posts, this posts is this variable we passedto our index. So now we can assess it as avariable. So as in for post in posts. Insteadof writing the title ad, now we want to writeposts, dot title. In case you're wonderingwhere we get this title from this title isthe title of the page of the posts does whatwe assigned it in the model. Suppose a titleand they should be post created ads. And thensome texts. So this shouldn't be boss dotbody. Right? Yeah, well, now instead of juston body want to make it like maybe only thefirst 10 words, they select the first 15.So we should be able to do something. Let'sleave it for now, then we're gonna changeit when we see what our output is. So nowwe can end this for loop. Now, when you'reusing a for loop in Django, templating, youhave to enter a for loop, even though it'sjust going to go through out the wall, codebeneath the for loop. So it's quite differentfrom normal for loop in Python. You know,in Python, we use indentations to know whento end a for loop, we use the end for to enda for loop. So now let's save this icon hereand hit refresh. Good. So we have Tommy'sblood, we about to deploy Django projects,we have the date and the exact time we createdthis. And then as you can see, we have allthe posts. So this is working pretty finenow. But what want to change is that onceagain, two things. First of all, we don'twant all these posts right here, because ifa user can read all the posts from the mainpage, then he doesn't need to click on thatpost. So we don't want all the posts whenhe wants me to like the first 20 words orsomething like that, or the first 50 characters.And then, as you can see, this is 11:30pm.This is level 32, level 32. Now 1130 is earlierthan 1132. Now we want the latest posts tobe on top. So as you can see, this is theoldest post. So if this is the way our blogis Dominus, the first post we write is theone that's always going to be on top, andwe don't want that. So now let's go back inyear, and then, to make the latest post beon top are gonna say for post in posts, reverse.This is very easy. They'll say reverse, I'mjust gonna reverse it for you. So we got thisreversed, D. So now as you can see, the latestone is what is on top installation, Djangobest way and now to deploy Django. So thelatest one we add is one that's gonna comeon top. So we have that. So guys, what we'regonna do next now is to make sure that itdoesn't show all the characters of the postsor the old body of the post. So I'm gonnadie in the next video. Welcome back to thesecond video in this Django blog tutorial.This is a second and last video. So in thelast video, we stopped at getting all thelist of blog posts, and then making them orderin, according to the latest posts. So at first,when we put it, it was showing the oldestposts at the beginning. But now the latestpoll shows at the beginning. And I said inthis video, we're going to continue why. Asyou can see, all the blog posts is showingon the front page, which we don't want onlyones like 10 words, or 20 words to show thata user should be able to click, and it willtake them to another page to read the wholetext. So that's what we're gonna do in thisvideo. So first of all, let's remove all thesewe don't like the way all the bullets is showing,so let's change it to lock on it 20 or 30words. So right here in VS code, we just needto add impose the body will say, truncate,truncate words. And then we'll put a colonand say 20. So this is going to truncate itto just 20 words. Now when I hit refresh,you can see now I only have 20 words, I needto automatically put this three dots, whichshows that you can continue reading when youclick on it or something. So as you can see,only the first 20 words are showing, whichis looking good. So what I just need to donow is to make sure that user should be ableto click as you can see, now just plain textis I can't click. So let's make exactly andthen we're going to take a user to anotherpage. So right here, it shouldn't be in thisold class. So let's add. So right here atage 80 going to know where For now, let'sbase that back. So this can't calm you'reon this gun calm here. So let's save these.So this should be going nowhere, but I justchecked. Okay, this is showing, but we don'tlike our old DS, as you can see show in linewith purple. Now, we don't want that. So wecan just easily add a simple styling. So theyjust we don't need to say style, we can justadd it in the queue this time. I said textdecoration should be none. So this is justgoing to make sure that all the styling doesn'tshow. Yeah. So as you can see the lines, theunderlines, doesn't show what we see of thisin purple. So very easy, I'm just change itto color, black. So good. But when I clickon it, it still goes through that same age,whatever. So now, once exactly gone, it shouldtake it to a dynamic and unique page. So everythingwe're going to be doing is going to be dynamic,you're going to understand that in a second.So let's come up now. So what page is theuser going to go to once they click on a post,let's go create that in the URLs. There'sgreat one, unlimited posts, save us thoseposts, and then we'll give it a name of postmust add a comma right here because the lists,save it. Right now we don't have any functionnew views named posts. So let's go createthat. So say, def posts, requests. And thenlet me just render a simple HTML page. Postdot html. So now we save this, but we don'thave any page like this. Let's create thatquickly. Right here. New File, because theHTML Okay, so we have with an S. So let'scome here and update that post return s. Sothat's good. And now what we just wanted todo is to make this kind of dynamic. So wewant to right now we can go to slash posts.But nothing is showing just a blank HTML page,which is this page. So we want to get allthe data so we once like once a user clickon this is gonna take us to that slash posts,but it's gonna be like slash posts slash oneslash post slash two. Friends page with differentURLs. So these blog posts since is the firstpost is gonna have an ID of one. So it canbe slash post slash one, this can be slashpost slash two, this can be slash post slashthree, if you understand that, and then we'regonna get all this dynamically from the database.So let's do that quickly. Right here, we canjust say, we can give it an integer or a string,just like a string to avoid any errors. Soa string, which is p k, so this is st slash,post slash a string, which is p k. So we cansee that coming to views. So right now weare collecting pk. And then what we just needto do is to say that posts is equals to thosedots objects, not written as the same justobject dot get the one which ID is equalsto Pinky. So once we have these, we just simplypass it to the HTML, let's copy that here.And paste. So what we're doing is, once auser gets this URL, so let's say is goingto be post slash one. I know that slash oneis the ID of, let's say, one of these of these.So obviously, this we have an ID of one becauseit's the first or maybe an ID of zero, maybe.But once we get the ID is gonna be passedin this URL from the URL is going to be passed.Yeah, you can see that this function is gettingthat PK, which is the name we gave it righthere. And then from that became using youto filter our database. So I've added a newvariable. And then once it's been assignedto the variable is posts, which is our Moodle,dot object dot get. So it's going to get tothat particular posts, which has the ID ofpk. So then once we have that, we're justpassing it to opposite HTML. Because we didindex dot HTML, we can go there now and accessthat post. So right here, let's just copythe index dot HTML code and use it. Let'spaste. But still, to me is blog. Birds goto slash posts. Okay, so we need to add somethingthat is slash one. Okay, so it doesn't havean ID of one, zero. So let's come into ourdata base. Cookie, no, I D, for now. So weneed to create a particular ID. As you cansee, for now, it sees very various ad typeposts as no attribute objects, so it doesn'tsee any posts with this particular object,which is kind of weird. But so what we justneed to do is to make sure that we are doingthe correct thing. So we're basically goingto come back here. Now URLs. So we're passingthe string as be gay ID. And then right here,we're collecting data and then filtering it,which is good. So post data objects, okay.So objects with an S, suppose dot objectsdot get. So now I come here, give it one.Okay, so post object is not iterable. Yeah,for sure. So what's the saying in post dothtml, every column here, as it gets here,was in a for loop to get this now, but inour index, because we said post dot objectsdot all, which means is getting it as a listor as a dictionary, or just a list of somethingso we can loop through it doesn't mean youhave iterable when it says something to dohis music and look through it. But when wesamples that object dot get only getting onespecific value. So we can look towards specificvalues, just one thing. So that's why it givesus this arrow dots post object is not iterable.So in our posts, you must remove days andremote produce. So now if we come here andclick enter, again, we don't have anythinghere because wising posts instead of postreturn is, but let's leave it at that. Butwe have this now. And then right here on tothe post. So our simples are try to pose acreated on posts. That's bad. But now we'renot truncating. Any words, we want every singlething. Now, let's see. So as you can see,it says how to deploy a Django project toRoku. And then it gives us all these. So thisis what we need. So right here, let's givethis on each one. Also, because it's in title.And then putting the rest is good. So let'ssave it refresh. So how to deploy a Djangoproject to Iraq. And then we have the datethat was created, and then we have to postfor these. So first of all, let's remove thisparticular a tag, we don't need that again.So that is gone. So right here, you can seethat this is perfectly working. But what wewant to do now is from the homepage, we wantthe user to click on this, I need to go tothat particular posts. So we have to cometo index dot HTML. And we'll say, insteadof going to an ash tag, says oozes lash boostswith an S, let's be sure. No one just booststhis slash boss.id. Just like this, now, theissue of everything working. Now let's clickon this, you see this installation of Python,the date it was created with with the oldposts, and let me go back again, or clickon another one, you see this mentioned thatparticular post. And if I click on anotherone, it takes me to that particular post.So this is how to beauty of simple, very,very simple blog using Django. Now you gotsome more advanced features, like very advancedfeatures like images, you can add comments,like he's actually able to comment, you canadd to different types of text, so the usercan design his text like fonts and stuff likethat, you can add various other things. It'sjust the basic, the basic fixture in our blogis the crud functionality, which is create,read, update, and delete. So a user shouldbe able to create a new post, which you cando from our admin panel, and then should beable to read the post. So as you can see,anybody can call me I read this, you shouldbe able to update the posts. So if I comehere, installation of Python, and I say installationof Django, and I say safe. And I come hereI need to refresh. As you can see, it changesto Django, it should change to Django, becausethat's what we designed it for. So I reallyhope you guys enjoyed this video. And is actuallyalso be able to delete a post to Konya anddelete a post is going to delete higher. Sowe think the leads Yes, I'm sure with no meon each refresh, it's gone. That's gonna beall for this video. Once again, I really hopeyou guys enjoyed building this with me. Hey,guys, welcome to this video. In this video,we're gonna be using Django to build a weatherdetector up, so is just gonna get the currentweather situation in a particular city, whichis a search for. So right here, if I justsearch for London, and I click enter, it saysLondon, it gives me the country code, thecoordinates, the temperature, the pressureand the humidity. So this is what we're goingto be building in this video. So the templatewhich has this HTML file, and the source code,which is the final score to define our project,everything is going to be linked in the descriptionbelow. So you can check the description toget the source code for the front end andthe back end and everything you need. So havingall this said, Let's dive straight into thetutorial. So guys, the first thing we needto do is to first of all create a new Djangoproject. So we're going to create a new Djangoproject now and we're gonna name it weatherdetector. So to do dads we have to say inDjango admin, start project and then we'regonna say weather subject to something likethis. Then we just hit Enter. And now thisis gonna create a new folder named weatherdetector in the directory under folder isgoing to contain the Django default boilerplate.So we can say, CD does go into that folder.Now we are in this folder. If I press dir,I'm going to see now that I have managed spy,and whether the data. So after doing this,we can just immediately create the Djangoapp we're going to be using for this project.So I can say python manage.py. Start up. Andthen we just want to name this weather likethis, then you'll see a new folder is goingto be added named weather to doodies. Noisy,we have weather. Now we're going to importthis project into Visual Studio code. So I'mjust going to open up VS code. And then openfolder. So I'm going to open up that folderin VS code. So I have it in weather up weatherdetector. So this should just go ahead andopen my project right here. So let me justclose this up. So what we are just going todo now is to just glide with configuring ourtemplates. So as I said, in the introductionto this video, all the source code to everythingwe're going to be doing on the template file,I'm gonna link it up in the description below.So you can get to the template file, whichis the HTML file, and the source code to yourfinished project. So if you are stuck anywhere,you can easily just check the source code.So we're just going to create a new folderin the root directory, and then we're goingto name it templates. So now let me pop upmy terminal, or let me just use my commandprompt. Python managers view I run Siva. Sowhat I'm doing now is that I'm running thisproject we just created on our localhost,so Django is going to run it on localhostPort 8000. Just gonna copy these, come upinto my browser and paste it. Now you cansee it's showing us that yeah, this installationworks successfully, what we don't want tosee is what we want to see is our own HTMLfile, our own template. So let's go back towhat we're doing right here. In templates,we're just gonna get our HTML template, whichwe want to use, and then we're going to fixit into this template folder. So this templatefolder is just basically going to containall the HTML files, which we need all ourtemplate files. So I've got my template fileright here, which is indeed the HTML. I'llsay it once again, that this index HTML fileis going to be linked in the description below.So I'm just going to drag it pastes in templates.So now we have that. But you know, that'snot enough to tell Django that it should renderthe page. So we need to come into weatherdetector, which is our main project. And thenin settings.pi file, we're gonna scroll downto where we see templates. Now see templateshere, that we're gonna look for. Here's wherewe see dir is right here to save base dirslash template. So what's templates? So whatthis is doing is that it's telling Djangowhere to look for our HTML files. So anytimewe request a want to render an HTML file,is going to come into base directory slashtemplates, which is basically in this folder,where we have our HTML file. So after doingthis, let's just add the app we created, whichis weather. Let's add it to our installedapps. Nice. So now we can save this. But again,this is not enough for Django to render thatHTML page. So now we need to go to URL routing.So right here, you see that once we come tothe home page, we have this default Djangotemplate. So to Django, where to look fora template, but have not told Django though,when a user comes to our home page, what HTMLtemplate should you render. Now to do that,we need to use URL mapping or URL routing.So we're going to specify that once user cometo this URL, which is our home page. It shouldrender that index dot HTML folder, which isright here. So right now, I'm just gonna comeinto weather. So we need to create a new filenamed urls.pi. Right here These URLs are pwise where our URLs is going to be stored,say from Django dot URLs, imports, but toour importing path, which is going to allowus to specify different URLs. And you'll seefrom the views from your import views. Soalso important views, I'm going to explainwhy we need this in a second. Now what weneed to do is to have a new list named URLpatterns. Now it should be equals to path.And then we'll say views dot index. And theywill say name should be equals to index. Now,what we're doing right here is we're importingpath from Django URLs. So is a default Djangofunction, which allows us to specify a differentpath right here, you can see where we useit. So this from dirtybird views is basicallythis file. So we're importing every functionwhich we have in this file, every class anythingwe have in this file, why putting it intothese URLs with pure. So now, when we specifya new this year, the URL pattern is a listvariable, which is going to take a list ofall your URLs we're going to have on thisour site. So the first URL, which I specifiedis the homepage, that's why it's blank. IfI want to specify, let's say, slash signup,it should be something like, let's say register,this is how I'm gonna do it. I can just leaveit blank it just register or is login, I cando exactly the same thing. Something likethis. Boss, this is the homepage, I can justleave you blank. Now Django knows we're talkingabout this page, the home page. Now when Isay views dot index, or I mean is from thisviews.py file, which we imported, go to theindex function. Now the index function iswhere we're going to tell Django what HTMLtemplates or whatever we want to do, whichwe want to render. Now, this name is justbasically the name given to this particularURL. So whenever we want to request for theURL, or go to that URL, we use this name.Now we can just save this. And now we knowthat we don't have any function named indexin views.pi, we need to do that anyway, youknow, create a new function, I'm kinda silly,name it index. So this index wants you totake a request. So we're just going to sayreturn, render, and then request. And thenindex dot HTML. So this is requesting forindex dot HTML in Templates folder. Nice.Now we can save this. Well, we could callright here on each refresh, it still doesn'twork. Now, the reason why this doesn't workis because we configured all these URLs onlyin our app, we also still need to configureit in our main project for Django to knowwhat we're doing. So we come to weather detector,which is the main project folder. in there,we go to urls.pi. And then we scroll down,where we import path, we also want to importinclude, after importing include in the URLbuttons, which is here already, we didn'twrite this is there already, we can just saypath. And then we'll say include with thetwo arrows. Now what this is doing is thatwe're creating another home URL, we're nowin the URLs. py file of the main project.And then once it comes to this room, it shouldinclude whether or not URLs that means whetheris this app, which we created right here.And then we go to the URL spy file of it.And then anything we do to the same path iswhat should be done. Yeah, it's just includingthe URLs. So if I come here, you see we havethe same blog path. So anything we do here,I was wondering is taking views dot index,our are we doing a view dot index, renderingthis index of HTML. So now when we come backhere, and just hit refresh, now you see thatwe have this HTML page. So for now, you cansee all these are just dummy data, countrycode, country code coordinates coordinates.So what we want to do now is that we wantthe user to be able to search for somethinglike London. When is it enter, we want toshow the current weather details or weatherstatus in that particular city? So I justgonna come back to VS code. So right, yeah,the index. Now I went to the column into templates,and in index. So right here, we're going toscroll down. So what we want to do now, ifwe scroll up, you're gonna see that in thisindex, we have a form already. Now this formis using a POST method. The first thing weneed to do in this form is basically in thisinput, this search bar, which we have here.So this form is a post form, as you can see,using the POST method, in Django, anytimewe're using the POST method, we always wantto make sure to add CSRF token, somethinglike this. On the squat, okay. Now, once Isave these, and I call massage London, itgives us this error. Now, because I've notrefresh the page you see of the error, buttake a look at the error, we see it says forbidden.If I go back, I need to refresh. Now I'veloaded the new one. And I searched Londonagain. You see now that I don't have any arrow,nothing is working yet. But we've bypassedthat arrow, which is good. So what I wantto do now is basically just st this detail,this input right here is this input, whichwe see input type text name, city. And thenonce you click on submit it, you send thisdetail to this view, back to this index dotHTML view, is still what I'm sending you backto this page. But this time around, we wantto be able to get some details on things.So this is easy for us to do, what we justneed to do is just specify the data whichwas sending back. So right now, right here,what we're just going to simply do is comehere, when make sure that you set an action.And the action should be blank. Now the reasonwhy these action is blank is because whenwe eat so search is sending all the data,which is only one actually sending this Londondata back to this home page. Well, this timearound want to have something yes of countrycode coordinate, want to have the real countrycode, which should be London, UK or somethinglike that. And then later, we're also goingto remove these. So that's when he is afterhis country decides, by me, when his officecomes to decide this shouldn't be the onlysearch, we're gonna do all this also. So afteradding the option, and then we're able tosend now what we just need to do is to comeinto our views.py file, and then collect that.So first of all, collect the data which wassent, we'll say if requests dot method isequals to posts. They want to say, city shouldn'tbe equals to request dot posts. City. Nowwhat are we doing right here, when I cometo this page, from the normal URL bar, I'musing a get method to access this page. WhenI when I send a form using a POST method,I'm not sending a form to this page, the methodis different, as you can see now is a POSTmethod. That's why we're going to say if requestor metal is posts. Now the only time we'regonna use post is when we're sending a form.So we're gonna get if the metal is post, thatmeans obviously, the program's you know, theform is coming. Then once we know a form iscoming, we just need to collect the form,say request dot post CT. Now, this city isthis index, this input right here you cansee there's a name of city, if I change thisto place, then also needs to come here andchanges to place. But for now, let's go withcity to make this big again. Just go withcity, or then city top, you understood whatwe did, right? So we're just gonna save these.And then let me just first of all, after sendingthe city to this place, let me just pass itback to the HTML just to make sure we knowwhat we're doing. So we can do something likethis city. So we're just going to save andthen if I come here So it says local variablecity referred before assignment. Now thisunbundle Kira always happens, anytime youare using an if statement, and there is avariable been assigned without adding an elsestatement. Now we just need to do else. SitCT should be close to blank. Once I save thisand come back and eat refresh, we do havethe arrow again. So anytime we come acrossthe arrow in Django is always very, very,very common. You just can just simply usethat to take you over that. So right here,we have country code. Just see h1, and thenthere's a city. So right now, if I refreshthis page, and I hit London, now you see excuseme back in London. So that's just first verified.Okay, yeah, we're already passing a data valuefrom our page back to our page, as I explainedearlier, using different methods in a POSTmethod is tomorrow. But now, obviously, wedon't just want to see London, I want to seeis the country code, which is not really relevant,but I think is still key, we can get thatthe coordinates, the temperature, pressure,and humidity, so weather status, and detailsof the current city, which you search for.So for these, we're gonna be using an API,which is called Open weather map. So it'sa website, which has an API for you to use.So you can get those details from their website.But before you can use their API, you haveto sign up to their sites and then get anA, it's totally free. To sign up, you getyou can get an API, and I'm going to showyou how to use their API. So first of all,you need to come to your site, which is openweather maps.org. And then once you log in,you can just go to API keys right here, andthey are going to see your own key. Now youcan this is free to adjust in for testingpurposes, this is totally free, you don'tneed to buy a subscription or anything likethat. Nope. So we're going to be using thisAPI key to do what we want to do. So I'm goingto show you how to use the API gets the detailsof any city, we search research London, itwas such a cry, it was such a cape town withsuch Delhi, Mumbai, anyway, who can get thecurrent windows situation right there, righthere from our Python program, or Django site.So that's gonna be all for this video. Andthen we're gonna finish up these projectsin the next video. So guys, is the secondpart in this weather websites tutorial. Soin the last part, I stopped at telling youguys to get the API key from open weathermaps. So once you have your API key, you cancontinue to follow along. So this is the secondand the last part of this tutorial is justa two parts tutorial video. Now, this APIkey is very important for you to be able toaccess the API. After getting this API key,you can continue. Now this is where we stoppedads, which was where we just pass London backto this page. But now, whatever city is oursearch, want to get the details, what we'regonna do is go back into VS code. Now thatwe're able to send in data from this formto our views to our templates, we can easilyjust get that data and then get the weathersituation in that city. First of all, let'sremove these towers for testing purposes now.And this also. So now that we have done allthis, what we just want to do, we have thecity. So right here. So now that we have citywant to assess this open meta Maps API fromthis code, so we need some libraries, we needto import JSON. Now JSON is where as the JSONis, when we send a request to the API is goingto give us a response in a JSON format. Sowe need to import JSON to be able to actuallyget and then you know, pass or filter thisdata. And then we need to import URL lib thoserequests. So now that we have this done, weare very good to go. So right here, I'm justgonna say something like risks. Now this raceis the request was sending to open weathermaps. Now what I'm just going to do is tosay, URL, leave those requests that URL open.So I'm going to open a particular URL, andthe URL is going to be HTTP API dot open,open with a mob.org. Slash data, slash 2.5.Slash with question mark, then I want to passin some parameters, say Q. Now Q is goingto be close to the city. Now this city isQ is actually a totally means query. So it'sgoing to be close to the city that the citywill want to get the details of. And we useconcatenation at the city. After adding thecity, what we just need to add right now isour API key. So we're just gonna say an IDshould be equals to now those only inputs,the API key which we collected from you. Pasteit right there. So now we have inputted, wehave input our API key. So I'm just gonnasay dot read. Which two parenthesis. So nowthat we have this done, we're just gonna goon a new line. And then what I just want todo is to say lists. Let me just say JSON data.Now this is the data I get after sending arequest to this URL. So I'm going to say JSONdata should be JSON dot loot with an S inorder to load risk. Nice. So now I have thecurrent weather details of this city storedin this JSON data variable. But now I wantto make this JSON data, I want to change itto like a dictionary, a Python dictionary.So it's easier to access, I can just simplysay data equals two. So what I just want todo is to say countryshouldn't be streamed. And then from JSONdata, see s Y is and then we'll say country.So now after having these, we just use a commato get some other details which we need. Nowlet's see what we need right here. That wasamazing. Why puts this down. So we know what'sfunny, we need the coordinates, the coordinates.So another one is the coordinates. Now, theyactually have their documentation where youcan get out to use all these, but I alreadyknow how to use it. So you can just followup with this tutorial. So you can also getsome more things about that specific location,even more than with our situation, the guyswho are getting the coordinates are gettingthe country code. Now these are more aboutgeolocation. So you can use the API for somemore themes can just go check the documentation.But for now, let's stick with this. So coordinates,and then also a strange making sure is a strange.And then from JSON data, what we just wantto do is C o r d, and then another one afterit, I want to get the longitude, which isshort enough to learn. And then to concatenateif it doesn't look like it space or something.Now want to concatenate it with the latitudealso send JSON. And then what we don't needto do is also say, C or D. And then righthere, we're just gonna say lat, which is theshort form of latitude. Now comm put a commato get to the next one. So we have the countrycode, we have the coordinates. Now let's getthe temperature which is basically what weneed. Let's change it to temp strange. Andthen JSON data, then what we just need todo now is to just the main main exam, whichis the temperature plus gay. So this key isbasically in Kelvin, so it's not in degreesCelsius degree far away, it is in Kelvin.So you can also you know, use your Pythoncode to convert it very easily. But for now,let's just stick with Kelvin. And then let'ssee, we need to pressure and humidity nice.So just a pressure. We forget our pressurestring. JSON data mean other than preasure.Nice. So now you can just add our comma. Thenthe last thing we need is humidity. Humidity,then we say the same thing string. Then wejust say JSON data. There we just say meanand then we just say humidity. Basically.You meet the tea. Nice. So calsonic Homerjust to avoid any heroes, go right here. Andthen we can just come down. Okay. So we're,I think we're done with this data since wehave it closed here already. So now we alreadyhave everything we need inside this data sociosdata shouldn't be empty. So now what we justwant to do is after rendering this, we justwant to pass data. Now we can access thisfrom our HTML, which is quite cool. So nowlet's come in to our HTML. So right now, insteadof all these country code, coordinates, wecan just use these same thing for for thetemperature also, for the prayer, humidity.And I think that's what we need. So now let'ssave this. Let's just save these. And we comeback here. Now this is the key now you seethat there is nothing in the outputs. So nowthere's eight slon. Done. Now press Enter.So it says budget quiz HTTP, we come downhere. Unable to receive, so we are havingsome errors. Let's go and check was Yeah,from this line, the error is coming from thisline. So let's go see. Views dot p y. So let'ssee, most of the time, this happens becauseof HTTPS. Now, let's go back to our page,London, we eat enter. So we see the error,basically. So let's copy this URL in whichwe're trying to assess. And then let's openit in a new page, just to make sure that Yeah,everything is working. Okay, now, the reasonwhy we're getting this is because right here,there is no equals to. So let's go back andchange that. So you can see that wheneverwe are passing a value can see there's supposedto be q, which is a query equals to CT, thenapp ID equals this. So let's just say queryequals two then CT. So I think that shouldfix our problem. Let's save again. And wecome back here and search for London. Nowyou can see very, very good. We have countrycode. Great Britain, which is where I live,I'm just saying coordinates. We have the longitudeand the latitude, then temperature is sodre.74. points. 34k. Yeah, I think that's correct.Then pressure, which is DS unlimited D soever these which we need. And I think basically,that's all we need for this project to beworking. We can do some little tweaks likegoing back here. Right here in the index.We just want to have right here is like anh1 and then let's pass in. Gum, yeah. Yeah,this CT. So let's make sure the CT it goesto blank. Then, let's see CT is CT. No safeties,we come back here. In year we can put CT.Let's save this and check. As you can see,we have our page coming in as HTML. So I'mvery sure the reason is because there wasa syntax error right here. So go the dictionary,we just have to cut that. Do the candles dosomething like this. So let's save it andgo check it out again. So we eat enter withfour codes to run. Let's open that up. Sowe have an invalid syntax actually. So thereason is because let me come back here isbecause we are not Supposed to pass a dictionaryon, you know this like this. So we just needto dois this. So said data should be equals todata. Now let's save these. And then thisshould work back. Let's wait for it like twoseconds or so. Okay, he's reloading. Yeah.So now let's see, unless it's London. So nowwe have London. But you can see that we haveall these not showing. Now the reason whywe do have it shown because it doesn't seeit. Now, as a dictionary, again, it sees itas a normal variable. So we're gonna haveto come here, index, and we'll see data. Datathat data. So you need to add them. It Oh,and therefore humidity also. Now when we savethese, come here, but yeah, each refresh andsubmit again, you can see now we have London.And we also have all these details. So that'sbasically how to just fix that. So first start.So let's search for another city, actually,let's see legace. Now Lagos country good Nigeria,which is Angie, now we have all these well,cool temperature, then, let's see anothersetting and then we move on. So that takesus now to exhaust contract with us. And itgives us the details. Now this is what wewant in this video. One more thing that wewant to pass is when a user comes to thissite, we don't want this to show one displaysto be blank. First of all, there was a searchhistory show. So we can also do that by firstusing an if statement. So after rule, righthere, by going to say e if data dot countrycode. Then if we have these they should beout the country code should be we have theseinitial these else, which is our else statementalleges entity if we don't need else. Nowlet's save this and see each refresh boomis gone. So what we're doing is we're sayingif data does contract code, that means ifwe have anything like this, then you showall of these words, even though it's obviouslythis will not be there. So now let's go andcheck it again. London, we'd enter now wehave this border, we just come to this site.Normally we do have these are this is verygood. This is what we want. So I hope youguys enjoyed this tutorial, which was reallyfun for me beauty. And also, if it did, pleasedon't forget to smash that like button andsubscribe. In this video, we're gonna be buildinga simple chat application using Django. Sothis is going to be built with Django anda little bit of Ajax, so a little bit of JavaScriptin it. So we're not going to be using doinganything so complex, we're not going to beusing them WebSockets channels or anythinglike that, just Django on Ajax. And the linkto the source code of everything we're goingto build in this video is going to be in thedescription below. So the template file andeverything we're going to build, you can accessit. And this video is going to be in two parts.So this is the first part and you're goingto have a second part to conclude it. Andyeah, so let's go ahead and test this out.So this is the room name or user can createa new room or they just say let's give itlike a room of code Dean. I don't know I'mjust giving it any room and then less andUS team to now enter the room because he isblank for now. Let's enter that same righthere. We are let's enter as john. Now we enter.So now I can see I guys almost like it sent.You see it shows 42 this is a real time andI got a What's it send you see it shows 42so this is the simple application we are goingto be building in this video. Now all thesedata you're seeing here with the date andtime with the message and the name are goingto be saved in our database. So as you cansee, we're getting back all these messagesin real time. It's actually a fun projectto build, and you're going to improve yourskills in Django. And mixing is really a bitof JavaScript to even notice it. Let's divestraight into the video. So guys, the firstthing we need to do to get started with thisproject is to obviously install Django. Soas I said, in the intro, we're gonna be usingDjango to do this chat app. So let's makesure we have Django installed. So I'm justgonna say Pip, install Django. Now this commandline is going to install the latest versionof Django on my computer. But I have Djangoinstalled already. So it should tell me requirementalready satisfied. And note that if you'renew mark, you should type PIP three, installDjango. There's just a small difference betweenWindows and Mac, what, there is nothing morethan that. So as you can see, it says requirementalready satisfied. So let's just wait forthat to opt out. Oh, yeah, I cancelled it.So let me close this up. And now we can justcreate our project. So I'm in the directorywhere I want to create my project. So I'mjust gonna say Django tyffyn admin, startproject. Let's name it Django chat. This isit's Jango chat. And in this video, we'renot going to be using channels and readiesand the popular way of using a chat app, whatwe're just going to be using is a little bitof JavaScript, which is Ajax. So we're goingto be using Django and implementing Ajax tomake our chat functions real time. So you'regonna see what we're gonna do in this video.So right now, we can just go into that andsay, Django charts. So we are in this. Andthen if we press dir, we can see right herethat there's money.py file, and we have thisfolder. So let's just what I like to do isto create my Django app immediately. So nowI can do Python manage dot view, our startup our name, just name the app chart. So now,this should create a new app named charts.And we should have another folder right here,named chart. So right here, you can see wehave a new folder. So we don't need this commandprompt again, let's come into VS code. Andthen let's just open that up. So I'm gonnaopen a folder. So the projects we just created,I'm gonna bring it into VS code. So projectShut up. I have it in here. And it is yeah,this is it. So I'm going to say Select Folder,so it should pop that up. And give me someseconds. Okay, so that's done. Let me closethese anomalies. So now we have all theseright here. So the next thing that I wantto do, the first thing I like to do is tojust add my template file. So the templatefile, when I say template file, I mean theHTML files in which we're going to be usingin this project. So first of all, let me saytemplates. So I need to create a new folderin my root directory named template. And inhere, I'm going to bring in my template files.So I have this template file designed alreadyin this video, we're not going to be doingthat from scratch. So if you want to get it,as I said in the intro, I'm going to havea link to the source code of this projectin the description below. So you can go thereand get the template file. So right here,if I open this up, this is where I startedthe template file. So I'm just gonna dragand drop into VS code. So we have it rightthere. Now the next thing we need to do isto go to our settings, and just configurethe template and this add this chart to theinstalled apps. So first of all, let's comehere. And then there's our charts. So thatis added to the installed apps schoolzillaup and then we come down yet writing this,I can just say pays the day when I see theseslush templates. So what this command lineis doing is that it is telling Django whereto look at our template file. So when we aredoing the URL mapping, which means when welooked telling Django where all our URLs areall the URLs of our project, and we want torender an HTML page to show for a specificURL, we need Django to know where to locatethat HTML file. So this line of code saysdirectory so I don't need to go to the basedirectory. So the base directory shows theroot project right here. This is the basedirectory. And in the base directory, Djangois going to enter into a folder named template.As you can see, this is a template. So Djangocannot assess all this files inside this templatefolder. So let's say we instead of namingthis template, let's say we name it somethinglike files, Oh, we don't need to do is tocome here and change it to files. But yeah,we are using templates. So there is no specificname you have to give this is just make surethat this and this correlates. So yes, wehave that done. And then we can save. NowI don't think we have any to do with settingsfile, again, now we just need to do is toset up our URLs. So we've come here, and thenwe need to create a new file called urls.pi.To now setup URL, we're just going to sayfrom Django dot URLs, impulse pass. So thisis gonna allow us to be able to configurethe paths. So now let me just say from theinput view, so we're gonna use this and I'mgoing to explain why we're important thissecond line in a minute. So now let's sayyou are buttons equals two lists, the firstone, which is empty the root directory, weused or let's say home, and then let's giveit a name. So now we have this. So we're importantthese views, because we're saying that whena user wants to go to the home directory,it should go to the views dot home. So it'sgoing to go to views.py file, which is thisfile right here. And again, to look for afunction name. So whatever we're doing itfunctions, we're going to be happening tothis URL. So I just did a second like to importviews. So we can says any function we haveenough, which is right here. So right here,we have to have a function named home. I'lllet you just take a simple requests. And thenthere's return say return render. And thenrequests for now want to request for homedot html. So that's it, I'm gonna call meon it. So the last thing we need to do forthis particular URL is comes in Django chat,which is the main project folder, and insidethe URLs have to follow these ledges closesup. So right here in path after importingpath, want to import include, and then I'mgonna say was include charts dot URLs, andwe're gonna save. So now I'm going to popup a new terminal. And then I want to runmy Django projects just to make sure thatthis URL configuration works successfully.So let's give that a minute to set up. Soit's very easy to run a Django project toactually try to follow up with this video.I expect you to know at least some basicsof Django so you know what's going on aroundhere. But when in time I'm doing my tutorialsare like explaining everything I'm doing evenif you're not, you don't know anything aboutDjango so you know what's going on. But havingno basic knowledge of Django before watchingthis will be helpful. So to run our Djangoproject, we're just gonna say Python managed.pyrun server. So that's how easy it is to runa Django project. So I'm just going to waitfor that to run on the local host which islocalhost Port 8000. So okay, right. Yeah,it gives us an heiresses shrink add new objects.Oh, so we're gonna come here so it's safeon Nana it also cuz I guess it hasn't updated.We think gives us that same error. Okay. Let'ssee. views. That's boom. Here. It is not supposedto be full stop supposed to be a coma. Solet's save that again on should be running.Yeah, yeah, so dad's running on this. So ifI just Ctrl Click is gonna open these particularURL on my default browser. So okay, they justcome here and open it up ourselves. So you'rejust going to type in the localhost, whichis 12700 on port 8000. So that was open andready. And then we should see our HTML file.Good. So as you can see, now we have Djangocharts. And then we have the basic form, whichwe're going to use in this project. So thisis the basic HTML file we're using. So a userjust gonna add to the room name, and thenhis user name, and we'll be able to entera room. So let's head back to VS code andcontinue with the coding. So now we can justclose this up. So let me just open a new terminaldown because we're gonna need it later. Sonow that we have these, what I want to dois to set up the model that we're going tobe using in this project. So I'm going toset up two models, one is going to be forthe chatroom, and the second one is goingto be for the messages. So I'm going to comeinto models.py file. So right you, all I justneed to do is to create a class, I'm goingto name it room and gather models dot model.And the only thing I want this to averageis the room name. That's all Mojo's towardsJakarta field, and unleaded max lens of 1000.So that's what the room name. So I would havegiven it another attribute of ID. But in Django,each model objects as an ID generated oneif a new object is created. So like thesedays, another attribute named ID Oh, don'tneed to write that ourselves. So this is goodto go. And the second one want to create isthe message. So this is the module or thedatabase that is going to be storing all themessages. So say models dot model. Right now,I just gonna say value. Yeah, I think valueis a good name. So value is like the messagethe user wants to send like a Oh, you're doingwhat's up. So that value want to give it somodels dot character field, also, Max land,so a message can have up to like a millioncharacters. And then let's give it a date.So which date wasn't this. So before we canuse date, we need to import something nameddate time. So from date, time, import date,time. So we're gonna say models, dot date,time field, not only date, view, date, timefield, and then what want to pass in year,this is not going to have a maxlend. Whatthis is going to have is a default. So defaultswill be equals to date, time, dot now. Andthen let's just set blank to be true. Justcopy this, paste. So the next thing we wantto have is the user. So which user is sendingthis particular message that we want to usea ledger give it a million user name shouldn'tbe able to double it's just to avoid any errorsin this project. And then the last term Iwant to add is the room. So want to know whichroom is this projects been is this messagebeen sent to. So this room is going to belike, we can use another Django model, likea relationship model, like the many to manyof you the foreign key to link this with thisroom. But we're not gonna be doing that inthis video. So this is also another way todo this. So one was submitting a new messageis going to have the ID of the room, whichis going to add a link to this. So you'regonna understand all these in a moment. Solet's just save this. And what we just needto do is to migrate this to our database,so say python manage.py. Make migrations.And then after making the migrations, whetherit's gonna have to migrate, so that's doneby dawn manage.py. migrate. So, yes, we havethe migration done. Good. So it has been migratedto our database. So now we can go into ourDjango project and go to slash admin. Butbefore we can answer the admin panel, we needto create a super user. So Python money createssuper user. So let's just avatars admin, leavethis blank. Give it a password. Let's bypassgood So now we have a supervisor created.Let's close this up. So we need to registerthese models in our admin file. So first ofall, we have to import the modules from thosemodels, imports grew an important message,admin, dot site, dot register, register, boom.And then there's also register message. Nowwe'll save this. Now that come you go to slashadmin. Now he's gonna ask me to log in, let'sgive it a second to load. Nice, he says Ishould log in, let's gonna log in with thedetails that I just created. And then, asyou can see, now it does take me to this adminpanel, and I have the messages and the rooms.model, the Django model right here installed.So coming to messages. For now, obviously,we shouldn't have any object here. So whatif I want to add a new message, you're gonnasee that it has all the fields we need. Solet's just go back to the own. And then let'sopen a new tab, go back to the home page andleave this like this. So now we have all this.Next, next thing that I think we need to donow is to make sure that once a user put ina particular room name, let's say the roomname is Django, just Django room and the useris like, Tom. So what is the entire room,it should take a user to another unique URLfor that particular Django for that particularchatroom. So what we need to do is to firstof all, check if this room exists in our database.So if, let's say Django, for example, is thename of the room, I want to enter the room.If it's a new room, that means if someonehas not created it before, we first of allwant to create this room, and then enter,but there is a room that already exists, wejust want to enter the room and see all themessages. So let's just take this off, andlet's go through that. So first of all, weneed to let me remove this, we don't needthis again. So right in our URLs, we needto have a new path. So this path is gonnabe the path for the room, it's gonna be theURLs for the room. So I'm just gonna say soit's gonna be a dynamic one. So we'll saystrange, dudes name of Rome. And then we'llsay slash. So this is the Rwandan slash anythingwant to add to it. So say views. dots room,I'm gonna give it a name overall. So thisis good. And then let's come into views andcreate a new one. I'll name it room associateroom request also, under just copy this, itshould also render the room dot html file.So this is where the room dot html file is.So it's rendering the room dot html file.Very simple. And now, what we just want todo, so this is not just taking a request.First of all, as you can see, right here,we're passing a variable into this particularURL name room. So we need to come into viewsand also collect. So now we have all thiscollected. But if we come into home dot html,so right here, scroll down, go down, down.Right here, we have this form. So want tosend this form to an action that was a userclick on Submit. It's your first sent thosedata to a view that we check if this particularroom as I said or not. So let's let's createthat view. So we need to create another URL,actually. So let's name this check view. Sothis is a view that is going to check forwhat's going on. So Oh my God, why is that?So let's just copy these views. The checkroom is the name of check row, as Michelledesign, comma, and they're right here in ourviews. Let's check room. Just think request.For now, let's pass. Let's save these knowingkomiya and save these. So now we have thisURL. So if I go to slash anything is automaticallygoing to see that as a room. But what I wantto do now is to come into my own dot html.So right here in my home that HTML, I wantto add some things to my form. So this isgoing to be easy just to add where this datais going and stuff like that. So first ofall, let's say the method it's using to sendthis data is a POST method. And then the action,where is it going, it's going to check foryou. So now we have the room name, the username. So in Django, we are using a POST method,we must make sure that we have the CSRF tokenCSRF underscore token. So you must make surethat we have this obviously, now we have theroom name, and then the user name. So thisis good to go. So now we are sending thesewith the room name and the user name to thischeck for you. Now, right here in the checkview, before we do anything, we want to checkif that room name exists in our database.So before we can do that, first of all needto import that particular model so safe from,we can see those models, or we can see fromchat those models anywhere you want to doit is fine. From standard models import, wewant to import room, I want to import message.So for now, we don't need message berlageas important down because we're later goingto use it. So right here in the jag view,what we just want to do is to say room, becausethe requests dot posts. And then bescom yummyshower. So does a name of room name. So we'regetting this name, room name. And then thesecond one is the username, obviously. Solet's make sure user name correct. So a personDS, and then what we just want to Jake wasgonna say if room dot objects dot future,so our future needs file t name equals room.Now want to check even this exists, then let'sdo something. So what we're saying right hereis that if a room got object of future damage,it's gonna check even if there is an objectin this room model, which has the name ofroom, so the name of this room that the usersent. And then if that exists, wants to dosomething, what we just want to do is to redirectthe user to this to the room, which is a trimfunction. Before guys redirect, we need toimport it. So import redirects. Good. So wejust say, return redirect, and we're redirectingthe user to slash room slash room dot name.And we don't need to say that name, becauseyou already have that name. And we know itexists. So we're redirecting the user to theroom. And then what want to pass also wantto pass the user name of the person that wantsto enter this room. So we know we send ina message with entering and doing stuff likethat. So now, we can just say slash user name.So right here, first of all, we should havelike, these user name should be equals tounreligious. Add the user name. So that'swhy we took tissues and so returning the usernow, to slash room slash user name, then equalsto user name. So this is good to do workingon then even doesn't exist. So if this isa new room that the user is just creating,but want to do is rather new. To have a newvariable, say new underscore room should nowbe equals to room does object dot create.So want to create a new one with the nameof room. So we're gonna get that room andthen create a new room with that particularname. So now we just say new room built safe.So now once we have this saved, we can redirectthe user to that page. Exactly the same thingwe did here. So I hope this you understoodwhat we did in this check view is pretty basic,pretty simple stuff. Religious safety safeties,and good test it out. So right here, doesit refresh. Let's go to our rooms, he willsee that we have no room to let our new roomunless you say something like, let's giveit programming. They just say programming.coders. Okay, good. And then they say, Tom.So now let's create a room. Now you can seeeverything is working perfectly. It takesus to this particular URL named coders. Sothis is our app slash go does then user nameequals to. So we are the name of the room,and then the user name, so the user that enteredthe show, and then when we come here and eatrefresh, we can see that our room has beencreated successfully room coders. So thatis good. And then don't mind this messageor see now that's just the basic templatethat we brought in earlier. So this is whatwe're going to change this to be real timemessage, and oh, or deciduous, or demo. Andthey are going to change this to the roomname, obviously. So I think we have these,and then let's check. So let's go back, andthen try to enter this cooler room again.So now let's make sure that he doesn't createanother room with that same name of CUDA.But he just takes us into that room. So let'senter with another user, this time I couldchange. So he brings us to that same room,but with a different user this time around.So once we hit refresh, we see that we don'thave a new object created, it just takes usinto this existing one. So that's what wedid in our check view. So that is pretty goodright now. And then, since we have these,or we can just do is to come into room dothtml. So right here, this is where we needto do some work. Next, I can just close thatup. So instead of having name, okay, let'ssee, right here. Okay, good. So now we haveall this grated, the next thing we just wantto do, first of all, we're going to removethis. And then once a user input a message,and it's sent, we want the message to be storedin the database with the details of this roomand the user. So you're going to see whatwe're gonna do. So right here, now, what wejust need to do is to first of all, come intoroom dot html. So right here in this form,we need to create some things which are goingto allow us to submit that obviously, so inthe form, we're going to listen, the form,right should be down below, discloses. discloseDSL. So this is the form here. So now in thisform, let's just have some things like CSRFtoken, as I always have CSRF underscore tokento this, just to make sure that whenever weuse a POST method, everything works. So youcan see now that I put a CSRF token by I didn'tdo something like method posts. So that'sbecause we're going to be using Ajax to submitthis form. So if I come here, normally, andthen I type in a message and it's sent, thatpage is gonna reload. And that's, that's whatwe don't want in our chat. So we want youto be real time, want everything to happen.Without this page, even thinking of refreshing.So once we hit something is gonna send I wasit sent without page refreshing is gonna becreated in our message database. And thenlater on, we're also going to make it showyou automatically in real time, without anypage refreshing. So this is where Ajax comesin. So Ajax is a very cool feature. I havea ton of tutorial on Ajax on my channel. Soit allows you to do things like get databasein real time, asynchronously, some cool stuffsthat you can play around with Django. So thisAjax is not with Python is actually with JavaScript.So we're gonna be using some basic JavaScript.Now, to use Ajax. We just need to make sureis that You have this script loaded in yourtemplate file. So this particular line, letme just scroll across so you guys can seethe lines. That's it. So once you have thatimported, you are good to go. So first ofall, right here, you can see that we havethis form. So we want to click Send. So youright here, you see we have 1234 inputs. Butyeah, we only have two inputs shown. So ifyou see the type of this is eating, and thetype of this is also eating, so we don't wantthe user to write anything new, we're gonnaautomatically give it a value ourselves. Sothe user name is the current user that loggedin. And then the room ID is the ID of thisroom the user is in. So before we can continue,we need to come into our views, get thesetwo details, after getting details, we passit back here, and then implement it in ourform. So let's do that quickly. So now rightin our room, we just need to say user name,first of all, so how are we going to get thisusername, you can see no bad, bad, bad, bad,bad, bad. So user name should be because nowlet's just go back and listen to a storm.Okay, good. So make sure our URLs is working.So you can see now our URLs, we have the nameof the room, and we have the name of the user.So since we have it in this URL of this view,we can just get back this details. So let'ssay user name should be equals to. So I'mgoing to request for its request that getsthat gets, Shall we do it. And then we'llsay username. So it's stored in a variableof username, as you can see. So now, in thisscenario, we're going to get the value ofTom, if this is theme are going to get a teamwith this area we're going to get. And thenext thing we want to get is the room details.So you can see that we have this room. Sothis code does is what is being passed herein this room, we have that read. So I wasgonna say since we have the name of that room,we're gonna use this name to assess the database.So we're gonna see room on discord details.And then we'll say it goes to room objectsdot get name equals from. So what this isdoing is that we have a new variable, obviously.And then from this room model right here,dot object dot get is getting the particularmodel which has the name of this room. Sowe have the name of coders in this case. Nowthat we have all those details that we need,all I just want to do now is to pass it intoour HTML. So right here, let's make sure weget that. First of all, we put a comma. Andwe have these. And then let's pass the username. Copy this past a user name. And thenone of us the room details also. So firstof all, what a buzzer room. Actually, if wehave the room details, we need to pass theroom. But let's just do that. Let's copy andpaste. So now we have all this sent to ourHTML. Now in our HTML, we should be able toaccess all this easily. So let's save thisfile. And right here in rooms. First of all,let me scroll all the way up. So instead ofroom name, now that I have the name of theroom, I can just do room. So this room isactually DCE. Okay, this shouldn't be days.Good. Save that again. So we have this room.So let's first see that change and make sureeverything is working. So instead of one name,we should have queued us. So right here nowyou can see we have queued us. Good. Now we'regoing to scroll down back to the form righthere. So the value of the user name is thecurrent user, we should just have these. Andthen the room ID should have real detailsthat Id like this. So I get in this room detailsthat was sent here. So as you can see, rememberthat the different details of the particularroom from the model. So what we're just doinghere is getting that particular model andgetting this ID remind the beginning I saidonce you have a new object, the object automaticallyOn ad, so I get in that ID. So now that wehave all of these issued, why we should begood to go with using our Ajax. So just useAjax, I'm actually gonna just open a new script,right here down below the body, as given here.So to save time, I'm just gonna paste in thiscode. So what this code does, you can seejust a piece of JavaScript. So let me explaineach line by line. So this is document. Sowhat this is doing is that once we load thisdocument form, we're saying that that alsomeets of this post form. So what we're sayingis immediately a user clicks on the submitbutton of this post form. So this is thisSubmit button of the post form. So what dowe want to do, we want to have a function.And we give this a value. So we'll say e dotprevent default. So what this prevent defaultdoes is that normally in a form, once we'dsubmit the page is going to refresh or goto another page. So this prevent default isgoing to prevent that from reloading or goingto another page. So now we know that the pageisn't going to reload. Now we're going touse our Ajax to send that details to our database.So what we're doing now is that we're sayingAjax, and then we're saying the type is postsnormally weren't using Ajax, we know, well,we're gonna use something like method. Butsince we're using Ajax, we don't need that.So already assessing the type post, and theURL is sending it to send, I'm going to explainthis URL in a bit. And then the data is justbasically what the data user name with theimage tag of username, room ID, and then themessage. So as you can see, everything isuser name, mighty message. That's just whatwe are sending. And then the CSRF token, thisis how we implement the CSRF token right here.So the success function, we can just say somethinglike message sent. So I just commented thisout was let me leave that like that. And then,yeah, let's just leave this like this. Sowhat this is, what this is doing is that thesources function damage if the message orsome debt to database, we're going to createa particular message. So this is going tobe accessed from the views.pi function. Goingto go back to that. And then this so whatthis is doing is that once a user it on sentand it has been saved in the database, wewant to delete these once we delete that particularline from the input. So what I mean is that,let's say user type something right here.And then these are it's sent. So once thathas been saved, we want to clear this particularinput to now be blank, just like the way yousee normal chat services. So right here, itgets this, this shouldn't be good. What wejust want to do is to have a new URL, andwe're gonna name this URL sent. So as youcan see, it's sending all this data to a URLname sent. So first of all, let's save thisup, and come up with a new one, say sent.And then we based and then we based so wehave a new URL name sent, then wants to createa new function for it. So just the way wedid something like this check view, remember,so this check view first checked, if thatroom is available, or not available, thenbefore it did whatever it wants to do. Sowe're gonna do something similar in the st.So we're just going to do, we're going toassess the st. So let's scroll down a newfunction sent requests. So these are justbasic functions. And then, right here, youcan see we're sending all this data to thisst. URL, so let's just access them. So we'rejust gonna say the message should be equalsto. So why isn't a Post's method from thefront end associated with quest those postsand then it's same message. So I like crosschecking to avoid any arrows. So here is ana variable message their room ID, then usea name. So those are the three we need. SoNope. gamier based based, and then this shouldbe the user name. And then this should bethe room underscore ID. So now copy that.just pasted the essence of the same thing.So we have all these done. So now that thisview as all this data, which to us are kindof inputted, or we just want to do is to storethat data in this message database, we'lllet that quickly load. Okay, I know why thiserror is coming up, just because we didn'tsave some changes yet. But let's keep going.So you know, we have this modules, which ismessage, so want to save all those into thismodule. So now, since we imported the messagemodule up here, remember I said we're goingto later use it, so we have that imported,we don't need to import it again. So we canjust say, new message. No new message, we'regonna say message is no just message actually,message does objects. Not slash Wait a dots,objects dot create. So I created a new objectright? Now the value, remember we used valueshouldn't be the message which we collected.And then the user, remember which user shouldbe the user name, which was collected, andthen the room. So what we want to store isthe room ID. So room should be equals to theroom ID. So now that we have this, all wecan just do just say new message that safe,so we just do new message that safe. So wehave that saved visuals, return. Now, we arenot rendering any HTML page, we just wantto return back to the front end or to theJavaScript the message. So we're gonna giveit an HTTP response. But before we can dothat, first of all have to import each year.So we'll say from Django dot HTTP, import,HTTP response. Good. So now we can see returnan HTTP response. We can say message sentsuccessfully. Good. So now we have this. Sothis HTTP response, this is how I just savedthe file. And this is our gonna, so this data,remember I said on success dummies, if everythingworks perfectly, we're going to function withthis value of data, and then want to alertdata. So this data is this HTTP response.So when we alert, it's just gonna say messagesent successfully. Now, we did pretty good.So let's go check out what we do. Now, thisshould be working. Good. And then in messages,you can see we have zero message. So now letme just type Okay, first of all, I got torefresh this page. refresh, refresh. Good.So now, let me just type a message like, Hey,guys, and I sent you can see it says messagesent successfully. Obviously, later in thetutorial, we're gonna remove this or justusing this for confirmation. And then onceI hit send, you see that the message doesn'tshow year again, which should be not as comeon it's refresh. I think now that we havea new message, so it says a guy's value. Andit comes from the user term, which we seehere. And then the room with the ID of one.So the room with the ID of one is obviouslythis restroom. So if it's another room isgoing to tell us the room with the ID of two.Let's cross check. No, that was awesome. SoI say okay, let's go to the home page. NowI want to create another room and say, backend developers. And now told me is going tobe here. Now let's create the room. Now letme see a developer's an IDE sent the messageand successfully the message displays is cleared.Now we come here to messages, we have twomessages now, a developer's we got the dateand the time, and it's coming from the userto me and the room ID is true. So if you'vegone to rooms, you see we have a new roomgreeted with the idea of a back end developer.So we can use this to assess the messagesfor each room later. So this is working prettyfine. We what we've done to this point isthat a user can create a new room, enter thatroom, so it's gonna be on a dynamic URL, andthen the user can send a message and thatmessage will be saved in the database. Soin the next This video, what we just needto do is to make sure that all once the userenters a room, all the messages of that room,first of all show will load like normal charts.And then once a user submits a message I needto send is automatically going to show righthere. And then not just only for the userfor also another user anywhere, the personis also going to test that with an incognitomode. So I hope you guys enjoyed this tutorialto this point, I really had fun building this.If you do not forget to smash the like buttonand subscribe. Hey, guys, welcome to the secondpart of this Django tutorial. So this is thesecond and final parts in this chat app withDjango. So in the last video, we stopped atsaving all the values into database. So weadd two models, which were let me quicklycome your messages and room. So this roomis gonna create a new room, whenever a userwants to create a new room, and then thismessage is gonna store the messages. So thismessage is like the database for storing allthe message. So as you can see, we have thevalue of the message a developers, we havethe date and the time, we have the user whichsubmitted our message, and we have the room.So as saying the room with the ID of two.So we didn't watch the last video, you shoulddefinitely watch that before these. So whatwe just need to do now since we have all thedata is stored, I think we don't have toomuch of work to do, we just need to get allthe data and showcase it to you. But we arewe need to do a little bit of extra work isto make sure that this data showcase in realtime. So if a user from another mobile phoneor from another place in the world, textshave also sent a message, we want to see itright here in real time without even refreshingthis page. So we're using Ajax for this lastvideo, we use Ajax so that when a user submits,so if I come here and say I testing. And thenI see that I click sent, it says message sentsuccessfully, this page didn't refresh, andthen it was cleared from you. Welcome to messages,you're going to see that I have a new message,I tested the date and time user and the roomID. So now we use Ajax to do that. Now wewant to use Ajax also, again, to load thesemessages data in real time. Let's get rightwith that. So right here, we just need toadd a new URL. So if we are just using normalDjango to just load the messages, you know,we're just gonna come into the views, we havea new function, or we don't even need a newfunction, which is going to come to the room,and then we'll just specify the message andsend it to the HTML file, and then just showcaseit. But if we do that, once the user updatesor create a new message is not going to beupdated in real time. So we need to make thatreal time. Let's go into URLs, we need tohave a new view for getting all the messages.And this URL is going to be dynamic. So sincey is in a dynamic URL list, copyright is pastthis. So this is slush gets messages. So ifyou can read these, this is saying that getsmessages slash a particular room that youwant to get the message. So we're gonna havethe room name. So if the room name is calledus, like right in your digital name of Jesus,but develop back end developers. So we'regoing to be like get messages slash back enddevelopers, they will say views that get messagesand the room gets messages. So this is good.And then it is going to come into our views.pyfile, create a new function, gets messagesshould take a request. And it should alsotake for now, let's pass. So now let's savethis. So now this is working fine. Now, whatwe just want you to do is to come here, andthen want to get all the messages of thatparticular room the user is in. So now thatwe know we have the room name, so we can usethis room name to get all the messages ofthat room. Now, when we get this message ofthis room, then we're gonna return a JSONresponse of all the messages. Then from ourfront end, we're gonna use Ajax JavaScriptto assess that JSON response and showcaseit to our user. Now, first of all, we needto make sure that we are importing JSON responseso that we can use that so right here in HTTP,we can say JSON response. So right here, nowwe're no longer gonna pass. We're just gonnado that to save room details. So this is anew variable. So was this in the room modelobjects that get on then what gets in theroom, which has a name of this room righthere. So now that we know we have that roomthat we're looking for, let's get to the messagesassociated with our room. So let's say messages.Good, should we get calls to message so thismessage, Moodle does object dot future. Andthey want to filter with the room, underscoreunderscore eight continues, don't worry, I'mgoing to explain this. If you don't understandit here. It's room details.id. So what thisline of code is doing, now, let me go backto what we did in the first tutorial. So righthere, a module created a new model name message.Now this message, what is is just the modelthat's going to be storing all the messageson this platform or the messages. And thenwe add four attributes, the value of thatmessage data, that message was sent to theuser. And now what we are specific about isthe room. So this is what I want to talk aboutthis room, is which room was this messagebeing sent from? Like, which room does thismessage belong to? Exactly, that's the word.So this room is just specifying the room IDof the message that this that this messagebelongs to. So now that we know that roomID, we cannot get all the messages. Now evercome back here into views. We're saying messagethose objects, the filter. So now we wantto filter with all the list of the data wehave here. With the room ID that's a containsthe room details.id. Now, I don't think weshould even say contains I think we're supposedto say with a room that equals to room detailsor ID. Now this is that more futuring withoutthe messages with the one in which the roomis this room details.id. Now, let's just returnin JSON response, return JSON response. Andthen let's return it's the middle variableof message messages, actually, let's say youshould be fine, then, at least obviously,we need to say that at least I will say messages,values like this. So this is returning a JSONresponse. And is returning it as a variableof messages. So this is what we're going tobe using to assess it. And then we're donedoes a list of messages, which is this messagesof value. So we're getting all the valuesfrom you. That's very good. Now we have thisdone. Now what we just need to do is to comeinto our room, dot html. So right here, thiswas the AJAX function we used in the beginningfor submitting the message. So for now, let'sjust comment that out. And I think we canclose this up. So right here, should be goodto have another script. So right here, we'regonna have another scripts. Let's just haveit right here. Good. So let's create a newscript. So in your I'm going to paste a particularJavaScript code. So what this code is doing,I'm going to explain how this code line byline. So this is saying that once we loadthis document, which is this page, then wantto want to do everything in this function.So this is set a set interval, what does thatdata What does is that anything inside thesebrackets are the function is going to be doneagain, and again, and again, with this particularamount of time, which is one seconds. So thismeans that all these Ajax function and gettingall the requests, everything is going to bedone every second. That's why we can assessthe data in real time. So once an update ismade the next second, we have that data updatedalready. So now we are now using the AJAXwe're saying get So this time I like gettinga particular data from the URL gets messagesslash room. So you remember when we did itright Where's that right here gets messy slash.So now we are giving you the room. Where isthe room? In our views, remember that in theroom view right here, we sent in room. Sothis room is the name of this particular room.So I think, yes, maybe this last particularname of the room. And then if we've got everythingsuccessful, and then so what we have righthere, when we are getting, we're getting thisJSON response, right here. So this is whatwe're getting you, then if it was successful,you can do console dot log response, we'regoing to show the response in girls, whichis that particular data. So I commented thatout, because we don't need it, but we justwant to do is to show it in our UI. And thenI said, display dot empty. So what this is,is, so if I come here, you'll see that I havea new div tag with an ID of display. So firstof all, I made sure that this is empty, Iremoved everything there. Metallic gonna removeall things I just commented out. So I removedeverything in there. And then I looped through,so I say for varkey, in response those messages,so for each value in this response, and thisresponse, which includes was JSON, it wassaying dot messages, as you can see is thismessages of everything we get here. So asseen for very key in response messages. Now,what are the new variable over just namedit temp? Just put that, and then now you cansee that we have this particular is it divtag in here. So this is the div tag we usein here. So we just specified a new JavaScriptvariable with the HTML tag. So is that thesame thing? So it's div class, container Doc,everything. But now in you can see that wejust added dummy messages. Hello, everyone.How are you guys doing? But right here doesknow what's out there. Again, right here.What is the IDS response? messages key dotuser. So this first of all, is the user nameof the person that sent the message. And thisis the value of the message, which is likea whatsoever, guys, and this is the date.So now we have this in an HTML tag, whileI was gonna append it to the div tag thathas this hashtag display ID. So now this isempty, then we're gonna append whatever weget into this div tag. So after having thatdone, I would just add an arrow. So if anythinghappened, if we add an arrow, we just sayan error occurred. So this should totallywork. Now let's save this up. So if I comehere, so back end developers? Yeah, let merefresh. Okay, so as you can see, now I havetwo messages. So if I go into my Chrome, there'sno Chrome, this is Microsoft Edge InternetExplorer or something like that. So if I comeinto my dev tools, and I come into console,now let me is refresh again. Okay, normally,I'm supposed to see all the data I'm gettingin real time right here, where I guess, notChrome. But you can see in this HTML is occasionallychanging every one second. So let me showyou what is going to happen right now. Soif I send something like WhatsApp people,and I say sent. So automatically, you seethat that we have that message here in theHTML, you see that is North Korea detailedin our code, but that's what that JavaScriptcode is doing. So this is supposed to showeverything, I guess, because I'm not usingChrome. I don't know why. But yeah, we canskip that, obviously. And then, let's see.Let's see. Let's see. Okay, good. So thesewere we're looking for network, not console.Sorry for that. So you can see that this isgetting some data every one second. So it'supdating. Updating, actually, this is noteven what I'm looking forward to. Okay, Iguess. So in caso were supposed to have, oh,yeah, I know why the problem is, so righthere in our sources function. We didn't weI remember, I commented it out. So let's savethis again. Is it refresh? So now you cansee, I have this message without reloading.So three messages for this particular room,a developer, I was a pastor. So you can seenow that we have three Good, let me have anew one like a, and then just hit enter. Nowyou can see we have four in real time is updating.So let me show you what is cool about this.I'm going to open a new incognito mode. Soin private window, I don't even think I'veopened this in his browser before. So I'mjust gonna add that there. Is these? Yeah.Okay, good. So where is that? We have you?Yeah. Good. So now, let me just assess. Well,in back end developers, so let's enter thissame room, or space states for now? We areI think we are Yeah. As to me. Now. Let'senter as john. And ls it enter room? Now yousee that it loads all the messages of thisroom? Now, let me say he told me are you doing?automatically, you see, it shows you and itshows in my own side also. So it's real time.So if someone is in another part of the world,it's gonna work. So let's say we post thisonline. And then we have two people connectedin different places, once a user sends a messagehere is going to show right here in my ownplatform a real time, as long as I'm connectedto the internet. So it's a pretty good feature,actually. So let's make sure we got no errors.And in this test is a game. So let's justgo to the home page. And then on the beach.So now let me create a new room. So let mesay, let me just say, code, let me just nameit code. And now let me enter as broad, somethinglike this. Now, interdivisional, you can seenow that there are no messages, actually,I can put something like, if there are nomessages, I should say, no messages in theroom or be the first sentiments of the likethat. We don't need that for now. So code.And then let's say that she's another name,Jessie. And now we need to enter. So now wehave these two blank rooms, to now say, awho's online. I'm 18. And you see, it's automaticallyshows here without any delay. And I can seeI am. And it shows here. So this is very,very good. So I might post this online, maybewhen I'm done with recording this tutorial.And if I do, I'm going to leave a link tothe description, the description. So if youwant to chat with me there you can. And Iguess we're pretty much done with this videois something's right here. Okay. How's Goodinggoing? Yeah, good. Good. Yes, of testing this.So yeah, this is very good. I love what webuilt in this video. With you guys love whatwe build. And you lie you like watching thisvideo. And if you watch this video to thisparticular point, I appreciate you becausenot everyone watches to the end. In this tutorial,we're gonna be talking about the Django restframework. So the Django rest framework isa library, which allows you to Butte API'sin your Django project. So let's say you havea Django project, or you want to build anAPI so that others can access your data, oryou're just trying it for fun, or just wantto build your skills, that Django rest frameworkis the best way to go. It allows you to easilybuild API's with a lot less code. So thisis this, the rest framework is very, veryeasy to set up. And I'm going to walk youthrough everything in this tutorial. So we'regonna start from the scratch, we're gonna,first of all, install Django, and then we'regonna start a new Django project, then we'regonna install the rest framework, and thenI'll show you how to integrate the rest frameworkinto that Django project. So without wastingany time, let's get straight into it. So righthere, I have my command prompt, and I alreadyhave it in this directory where I want tocreate my Django project. I want to firstmake sure that I have Django installed. Sojust pip install Django. This command lineis for installing Django using Python packagemanager code Pip. Like also install Djangoin some other ways, like easy install or justwith GitHub code directly, but this is thebest way to go. So I already have Django installed.So it should be telling me requirement alreadysatisfied. So we should give that a minute,it should bring that up. Now we already haveDjango installed right here. So it's takinglonger than usual. And then I can just getout of that. Let me just close by I have Djangoinstalled before, you should go ahead andinstall it. So now let's start the new Djangoproject using the Django admin start project.And the let's say, the RF, which stands forDjango rest framework approach. So Djangorest framework project, to that command lineis gonna start a new application or a newDjango project in this directory. So thisis a directory right here. So you can seenow that it is empty for now. And boom, yousee that we have a new project that has beenstarted. So let's come back. Yes. So now thatwe know we have a new project started, let'sjust CD into that project. First of all, sowe see we have a Django project and CD intoit. So as close that up by press di R, nowI can see that I have money, just Pew II anddi F. So this is my standard Django project.Now the next thing I want to do is to installthe Django rest framework. Before I installDjango rest framework, let me bring this Djangoproject into VS code. So let's open up VScode, close this up. And then in fall, that'sgoing to come to open folder. And then itshould take me to the folder which shouldtake me to the file manager. So I can go intothat folder I think is to F toots, then Chang,ti F. So this is the folder. And then onceI select that folder, obviously VS code isgoing to open that up. So as VS code is doingits magic, let's go back to the command prompt.And then what we just want to do now is toinstall the Django rest framework. So let'ssay Pip, install Django rest framework. Sothis is how easy it is to install the Djangorest framework, just a simple PIP command.So this command line is going to install theDjango rest framework on our computer. Soagain, I already have the Django rest frameworkinstalled, so it should tell me requirementalready satisfied. But for you, it shouldgo I understood that if you don't have thatinstalled, so let's come back into VS codeas that is installing. And then let's justmake everything clean here. So we can quitthis. So we can see that this is a Djangoproject. So for this project, we are not goingto create a Django app, at least for now.So later, we're gonna create an app wherewe're gonna use serializers and stuff likethat. But for now, we're just gonna stickwith just the Django project and the URLsof UI file in it. So that's where we're gonnaput our views.pi. And everything we're goingto be using. So let's come back to the commandprompt. As you can see, it says requirementalready satisfied. This means that I alreadyhave the rest framework installed. So nowthat I know I have the rest framework installed,I can use the library in other module in ourproject. So now, what I just want to do isto create a new file First of all, and thenthey rename it views.py. So in this views.pyfile does where I'm going to code just likea normal Django project. First of all, letme import render, say from Django dot shortcuts.So from Django shortcuts is the command line.Not command nine actually is the module. Sothe shortcode is like a class, I think likea function in the Django library, in whichyou can input some things. So we import render.And now, that's just for rendering a Normaltemplate for, but I want to use the API viewfrom the rest framework. So the rest frameworkprovides us with an API view class or function,or whatever it is. So with that API view,we're going to be able to access a lot oftype of API's that is available in the Djangorest framework. So when we use the API viewwe can do we can use something like a getrequest or port request. And some other thingsthat are being rendered or are being givento us by the rest framework. So first of all,say from rest underscore framework. And theywant to know the views, then we'll importAPI view. So I put in the API view from therest of the among those views. And then, asI said, this API view is gonna allow us tocreate a function or a class on it, so thatwe can be able to use all the everything availablein his API view. But we'll also is an APIview, we want to obviously send a response.Now, for example, let's say someone, anotherdeveloper tries to access our API, once itsends a request to our API, we'll want togive the developer a response want to givehim some sort of results. So let's say usersend a get request just to get a list of aquery set or something, or at least over data,want to give the user back a response or datadata? So first, give a response, we're gonnahave two inputs, response from the rest frameworkassociate from rest framework, import dotresponse, first of all, import response. Sowhat this is doing is just same from restframework that, Oh, nope, this is wrong. fromrest framework dot response, you just wantto import response. So that's it. Now thatwe have these everything imported, we cannow create a class to inherit from this APIview, so that we can get a lot of methodsthat we can work with. So let's just havea new class. And let's name it something likelet's say, test view. And then API view. Sothis was naming this, this view. And thenthis, this view is inheriting from the APIview, which is right here. So what we cando know in that order this class, we wantto have a get function, which is just gonnabe like a get request to this API. So said,Jeff gets, and then roughly says, self request.Alright, last arguments, and then keywordaccess keyword arguments, keyword x, justlike this. So now that we have these functions,what we just want to specify is a data. Sothis is a test view. And then in this test,we have a get request. So we want to likeaverage data in which we're going to sendback to the user or just give us a result.So same data. For now, let's just hard codeour data ourself. Later, I'm going to showyou how to use the jungle model so that thisdata will be like from the database you haveor something. But for now, let's just havea simple dictionary that we're going to sendback. So let's just have a dictionary sayingsomething like user name. Let me just seeadmin. And then number of years, I selectnumber of years, lots of the user has beenactive. And then we can give it somethinglike 10 years. So that's actually a good user.So this is just the data, the user name isadmin, and he has been active for 10 years,let's just make demo specific number of yearsactive. Remote these, we don't need that.So we'll just use active to last 10 years.So now we have this data that is in a dictionaryformat. So this is a data I want to send backas a response. So by just going to do is tosay return response of data. So what we justdid was that we use this response in whichwe imported from restaurant the response.And then we're returning a response of thisparticular data. So now we have this done.What we want to do now is I want to go seta URL for this so that we can actually testthis when we run it on our localhost. So nowlet's come into URLs spy, right here. I justwanna Remove all this needed. And then inyear, first of all, let me have a new path,which is going to be empty. Now this emptypath shows the own URL. So like when you justgo to your website, let's say like google.com,boom URL is that empty path. So that's that.Now, what we can just do is to first of all,import that test view from the views. Let'simport this video. So now that we have thisview imported, we can easily use it in here.So this is the UI. And then we can just saytest view. Since it's a class based view,we have to add.as view. Now the reason whywe're adding this.ru is because the view inwhich we're using is a class based view. Ifyou're using a function based view, you don'tneed to do that you can just say, test viewyear as the view. But since y is in a classbased view, we must do this even though it'sgoing to give us an error, and Django is notgoing to recognize that other valid few. Sotest view.as view. And the ledger gives youlike a name of something like test. So nowwe have all this set up, we have it linkingto the own URL using the test view.as view.And we'll give it a name of test. Now, I wantus to just run our server and test it immediately.But if we do that, while I'm gonna see nothing,we might even get an error. And it is whyam I getting an error is because right here,what we did was we installed the Django restframework. Immediately, we just came to startimporting everything in our project. But youknow, if you work with Django for a while,you know, you actually need to do some secondconfigurations, to be able to use some particulartype of libraries, not all. So for this Djangorest framework, we need to add some thingsto our settings. Now let's come into settings.pyfile. First of all, the first thing we needto add is in our installed apps, we need toadd where we rest framework, surprisingly,so right here, we need to add rest frameworkin our installed app. So Django is going torecognize it. Now after adding that as wellto do with the settings, what we just wantto do is under the URLs, we need to add oneURL in which the restroom Oh, my goodness.So first of all, we need to import include.After that, we can just pass API. I thinkfor both of them, we're just gonna do likea comma, and give you this a slash. And thenwe're just gonna include from the rest framework,dot URLs. So that is duffel, dat, and we'llgive it a comma. And then we can see. So now,we can easily come to a command prompt, andjust the Python managers Pew II run server.So now when we run this server, we can comeright here. And then if we go to the Oh, actuallywhat I'm going to use this for now, we justhave to set that Oh, because the Django restframework requires that. So when we go tothe UI, it should give us this test view.And this test, you should just be dockingget to just like either sending a get request.And then we're just gonna give it a responseor this particular data. So let's save thisalso. And let's come back and see what's goingon. So this should start running in a second.Because we felt that normally, Django doesn'ttake time to run by guest causes a new project,and we're running for the first time. So let'sjust give me a minute. Okay, so we have thatdone. And then let's come back to a browser.Let's open a new tab. In the new tab. Let'sgo into our local hosts with the port of 1000.Because that's Django default URL, somethinglike that. So give me the time to load. Okay,I can see the title loading already. Let'sgive it a few seconds and Yeah, good. So thisis what we see. Now, you know, We didn't designor this page or this fancy UI that we're seeing,we didn't design. That's what comes with theDjango rest framework, it actually gives youthis nice looking template to showcase yourAPI and basically test all your API's. Now,as you can see, is giving us in a dictionaryright here is giving us user name, admin ESR,tF 10. And that is exactly the same thingwe are writing in data. So normally, the APIuses it gives us a response in JSON format,that was given us a response in dictionaryformat, because those words, we actually setup right here. Normally, it shouldn't be aJSON format. So we're dealing with real data,real models, you're gonna see what I'm talkingabout. So as you can see, choosing the GETrequests, and then the HTTP two addresses,okay, so because it's allowing and get requests,because we specified the get function, righthere. Let me remove this safe. Because wespecify the get function right here. If wespecify the post function, we're also goingto talk about that soon. It's gonna show righthere that we allow in a POST request. So thatis basically the basics about this Djangorest framework. So if I come here, and thenI, it's Jason, you're gonna see now like,gives me this in JSON format. So right here,he just gives me a blank JSON format, no template,nothing, just a blank JSON formatted as ifI go to this URL. But normally, we just getthe homepage, this is what it shows us. Sothis is good. And I hope you're starting tohave a grasp of where the Django rest frameworkis above. Now, to be honest, it gets morecomplex than this layer, I'm going to walkyou through every single thing you need toknow to get started, and I'm going to simplifyevery single thing. So let's just come backto the rest framework page. And if we scrolldown, right here, in installation, you seethe exactly what is doing here is what wehave done in our project. So you can see itsays install using Pip, including any optionalpackages you want. So this is where we installthe Django rest framework. We can also installmarkdown on the Django filter, but we don'tneed that for now. Because they are optionalpackages. So you just saw the Django restframework, what is mandatory, or you couldjust clone the project from GitHub. Oh, Isee that as stressful, you know. So I justprefer using Pip. So what we just did wasto address remote, so I installed apps rightwhen we did it in the settings. And then weadded this URL pattern that I said, the restframework requires. So we've done all thatwe've gone gone through the installation,we've come Yeah, we've seen the results ofthe API's. And then let's move straight intoDjango rest framework serializers. Now let'stalk about serializers in the Django restframework. So serializers is a structure ofrepresentation that represents a data, wewant to return in a JSON format, or are savedin a JSON format. So we can use this realizethat to like transform our Django models intoJSON, let's first create a new app, and ourDjango project, and then we're going to dodeeper into serializers. So right here, inwhere we start, in my command prompt, I'mjust going to opt out of this server thatis already running. And then I'm gonna createa new Python, a new Django app for the smartproject. And we're gonna name it, whateverI want to name it, maybe my app or DRF appor something. So first of all, is of totalt so t should pick gun within a second. Andthen yeah, okay. So, okay, well, that wasa lot of press. So now we can just do Pythonmanager spqr start verse a DRF. So this isgonna start a new jungle up in our project.So when this is started, was gonna go aheadand continue with it. So, first of all, afterthis is started, we're gonna go into our modulesand create a module that we're actually gonnaplay around with. So let's just switch we'lljust do that. And that should be done. Withina second, give you a moment to do and see.Doesn't take time. So as that is doing, letme talk more about serializers. Actually,I wanted to explain more about serializers.Because we are getting started with the restaurantmock jelly takes a bit of a while to understandwhat these things actually do. So the serializeris a big about the lack of form, like a modalform. Once you have modal, the way you createa form for modal, so you can submit in Django,so you can submit a form, or update or whateveryou want to do. Think of that as a serializer.So serialize, I just basically the same thing,you have a model, then you have a serializerthat you link that model to and then you specifythe fields you want to be you want to be inthat particular serializer and enjoy GTO views.So that was the theoretical part. Now let'sdive into protocols. So right here, we cansee that DRF has been created successfully.Good. Let's remove that. So let's come backin now, we have to create a new file and nameit serializers dot p y. Now this serializersdot p y is the file where we're gonna configureour serialization. For now we're gonna leavethis blank. Now, as I said, we're gonna createa new module that we're going to use. So let'scome into module.pi. So writing a module doespure let's just create a new module. I wantto name this module like country. I changemy mind on me students are learning from themodels. That's Moodle. So let's give it somefears. And Alyssa, the name of the student,that would be muddles towards Sheffield, undercharacter feud should ever maxlend. Let'sjust say 100. Let's give it another one likeage. That's moodle.in teacher fuge. I don'tthink that takes any attribute. Let's givelike a description of the student who dealsdoes, it should be a text field. And thatdoesn't have any attributes, or let's saydate a route. And that should be a date timefield. So they'll be models dot date, timefield, let's say auto now should just be equalsto true. So I think we have these. Yeah, I'mhappy with these. And so let's just give ita string. Yep. And then as do the self onalleges average return, self name. Sonow we have this particular module. Now, youknow, normally in Django, when you createa new module, or you make any changes to themodules file, we need to migrate it into ourdatabase. So we're gonna do that right now.But before we do that, I want us to, firstof all register this up in our installed apps.So coming to sentence under right here, whatwe're just going to do is to say if that'sthe name of the app we created, so let's savethat. So now that we have that saved, whatwe can just do is to come into our commandprompt. And then let's just migrate associatePython managed. py make migrations. So we'llgive that a second to make the migrationsit might see no changes detectors. So I justlike making sure I make migrations and migrate.So I don't get any errors because sometimes,Django might be funny. So that should be doingokay. Yes. So, as you can see, it says createsmodels to dent biologists guide and migrate.So as you can see right here, when we saidmoney, those people I make migrations Butwhat he did was just to make some migrationdone Moodle student, right here is just migratingevery single thing into a database of adminof DRF. That is, that is what we want to see.So now that we have done migrated, let's goback into the serializers, that fewer. Sonow we need to import the serializers fromthe rest framework. And we also need to importthe post model from the models.py file. Andafter that, we can create a serializer forour post model by specifying only some fields.So first of all, let's do from rest framework.Import serializers. So now this is how weimport the serializer. So we can use it, justlike the way you use forms in Django. FromDjango dot forms, import forms or somethinglike that. That's just where we import theserializers. So let's also import that modulein which you want to use so from dots models,imports, students. No, we have these two thingsimported, we're just going to first of all,create a serializer class for that student.So say the class will be student serializer.And then we're gonna do from the serializersdot model serializers. So as you can see,it's quite similar to the form where we justhave like, if it was a fun one to use, wecan say student form, and it will say formson Moodle, very similar, if you're used tousing the Django forms, you definitely definitelyunderstand this. So knowledge is our classmeta, under specify, specify the model loadedwith the student, and then the fields. Sothe fields, let's make it a total. Let's see,let's just take two, so we just want the nameand then the age. So these are just the twofields want to use in this serializer. Nowit is that easy to specify a serializer toconfigure by any word you want to use. Sonow let's head back to the views.py file.So right here, right here, we're gonna importour post serializer and our post model. Soto do that, let's just say from that serializers.Reports, student. So I've already made a mistake,I said from the serializers. I said, we aregoing to put post serializer. But we are goingto put in post serializers why budget studentsrealize that we actually do have post, butI'm just going to use the same post as likea model, because that's what I use for examplesmost of the time. So why wasn't a studentserializer right here, class students serializer.So from serializers, which is DS, please makesure we have that. From just serializers we'reimporting the students serializer. Calm you'regood. So now that we have the students here,imported, let's just import the students model.So from the models, import students. So nowwe also have that imported. Let's go me andmake sure that's correct. Student Yup, thatstudent. So now that we have those two thingsimportant, let's create a POST method in ourtest view class. So in this video class, we'regonna create a POST method. So we can receivedata, just like in a form. So to do this,we'll just add a function below in artistswith class right here. We'll say def posts.Now this is going to be a post not to getand then you just gonna take exactly the samething that should be self. Exactly the samething. And there's going to be self requests.And then keyword. So now that we have thatwas gonna spit for our serializer in a variable.So this URI lives equals to sudents serializerunreligious give it a data. So when we dosomething like data equals to request. Sothis is a request towards data. So when wedo something like this, or it means is the,we actually want to use a form or want tosubmit a detail something like this, we'llsay data equals request or data. So beneath,we're going to see if serializer is valid.So first of all, check if it's valid. Whatwe just want to do now is to say serialize,a dot save just exactly the way we do in aDjango form, I'm always referencing to thatDjango form, because it is very similar tothis. I said earlier, if you've worked withDjango form, before, you understand what'sgoing on right here. So serializer data. Sowhat I just did was, first of all, we specifythe serializer. But our serializer is thisstudent serializer. So normally, if one wasin a post, like, if you don't want to submita form, you can just remove this as a serializedbecause students realize what I said, becauseonce you submit something like a form whohas to say data equals to request or datait needs to get the data which is being postedinto this particular API view. So let me getthat we'll say he does realize that that isvalid. That means if all the values valuein blue are correct, just like we want tocollect an integer field, of course, we wantto have an integer field, if we're supposedto call it an integer field, we have all characterfood or Tex food, then that serializer isnot valid. So this is just checking you isvalid if everything we want, even if valuesare correct. And if it's valid, we'll justsave it to serializer dot save. And then we'lljust return the response of that particulardata, which is awesome. So you know, justlike when you save a data, we just want toshow it back to us. So So data has been saved,this particular data has been saved. But ifthese don't happen, we'll just return a responseof an error. Sources serializer dot errors.So that is it. So now, let's save this. Andthen let's call and just roll our server onceagain. So what I want to do now the serveris running. We want to test this particularAPI in postman. So let me first of all, waitfor that to load up. So okay, that shouldn'tbe done. Okay. So it says, module not foundno module named DRF. Project serializer. Theone this is saying is that if we come backto our code indirim find a particular. Okay,good. So what is the saying is that he didn'tfind modules, the serializer that was theserializer ndrf proach. So we're importingthis dot model dot serializer. We're supposedto import it from you. But as you can see,we were importing it for me. So normally,we're supposed to use like the views dot view,in our project, actually, we can still useit in. In this place, no one is was usingthe app, but because he's in the project,we just need to do is to make sure that weare bringing it in from yours. Let me justsay, from those D, F serializers. And thenfrom the d r f dot models, so we can justsave this and that should work perfectly fine.So now let's see if our data renewed and thenit should run without any errors and goodso As we can see, everything runs successfully.Now, as I said, Let's come back to our browser.As I said, Now we need to test this API todayis an application called postman. So let meopen a new tab and show you to get a smileyou'll need to do is type download postman.And then once you type that you just hit entersuch it. So postman is an application, orsoftware, anything you like to call it, whichis used for testing your API. So since ourapp is doing production yet, or prigionieri,production is on live on the web or something.For some testing locally on our locals, wecan use this application code customer. Soright here is going to take you to the website,we are going to download the code. So it'sgoing to automatically detect your voice.So as you can see, it changed to Windows becauseI'm on a Windows, download it just installedlike a normal app, or the wind installer,most of 2008, you should be good to go. Sonow that we have postman installed, I haveit open right here. Well, I just want to dois to create a new tab right here. And thenwe're going to test the API in which we justcreated. First of all, I'm gonna come in hereand then copy. So I'll copy the URL, becausethat's the URL I'm gonna be testing anyway.So right here, I'm just gonna base This isthe URL I'm gonna be testing. And I want itto be a POST method. So right here, I'm gonnacall into body. So and then I'm going to clickon form data. Now I'm going to input key.So this key is where I want to submit. Solet's see, we'll come back into our VS code,we come into our serializer, we can see thatthe fields required a name, and age. So weknow that in our models name is a characterfield and age is an integer field. So to avoidany error, we need to make sure that we abideby everything. So name, does give you thevalue of admin. And then key, that is theage range, just give it a value of 25. Now,if we sent sending the request is our postmanworks, it's gonna tell the API for you. Andthen gauge so as you can see right here, name,it gives us a response of this particulardata name, admin, age 25. But how do we knowthat this particular data has been submittedinto Moodle? So what wants to know is, asthis data is really saved in our database,for us to be able to do this, we need to check,we need to open up our admin interface, andset up our admin panel and then check ourdatabase. So let's quickly do that. Firstof all, let's go back in here, we're gonnacut out of this server. So now that we areout of the server, what I want to do is tocreate a super user, so I'll say python manage.py.Create super user. This is going to promptme to input my user name. And my email mypassword, just like I'm registering for aplatform or for website does exactly the samething. So let's give it a moment to your,so I'm just gonna say admin. I'm gonna leavethis blank. I'm gonna give it a password.Yeah, bypass and good. So now let's run theserver. Again. That is running, we're gonnacome into our VS code. And in the admin, thePew II, well, just gonna first of all, importfrom dot models, import students, and theywant to register that student in our admininterface. So admin, side or register, students.So now this will show light as we registerin admin panel. We're gonna check that ina minute. Please make sure this is runningGood. Let's come into our browser as opena new tab. Let's go to slash admin. So Butas quickly do that right now. And then loginusing the admin info. Okay, good. So now wecan see the under DRF app, we have students,if I click on me, we should have one objectsin there. So as you can see, we have wantto dance, which is admin. And we submittedthat from our API. We didn't create thesefrom this admin panel, or from our projectsor from our website. It's true, our API. Nowlet's go test that one more time. So we havethis API, we have the name, alleges give yousomething like admin two, and then admin twois 27 years old. So now when I send, becauseit gives me admin to 27 years old. Now thereason why it gives me this is because ifI come back here in our code, we'll see thatI said that, if it's valid, it should savethat data. And it wants to save that data,it should give us a response of serializeddata. So that means if that is successful,the response I want to get is the data inwhich was submitted. So if I come back topostman, anytime I get the data I simple ideaI submitted it means that was successful.So let's come into our admin panel, it refresh.Now we have another one right here. So that'show to submit from our API. Now, that is cool.Now let's talk about serializing, the datathat is going out, and I mean, the get method.First of all, we already have model registered,we already have created a super user. Nowto use our get method, we're gonna come backinto our fear school. Now, what I'm sayingis, as you can see, this get method righthere, when we did it earlier is just a blankdata, just a normal dictionary, by in thispost method, in this post function, we areusing serialization, let's serializing ourdata. So let's say want to also serializethe data in this gate. Now all we're gonnado, since we already have self request, argumentand keyword argument, we're gonna specifya query set. So let's get rid of these panellasilica query sets. query set can be students,those objects does all know what we can justdo because this serializercan be equals to students serializer on thewater specified our query sets, and we needto specify one more thing insane. Many equalstrue. Now, the reason we need to specify manyequals true is because this query set is alist of objects. So from this student module,we're getting all the objects I want, whatI mean by object is right here, all the datawe have in this student database, the studentdatabase or the object. So as you can see,it is more than one is going to bring a listdoes where we have to specify many equalstrue items is more than one. So after specifyingthe query sets in a variable, I just haveanother variable named serializer, which istaken from the students serializer. And Ipass in the query said, Alan, I have to tellyou that many is equals to true. Now if itwas just one data, but yeah, just one particularobject or something we can just put squarehe said, was since is more than one aftermany equals to true. So now that we have thatwe cannot return a response of serializerdata. So when a user tried to, say this APIusing a get method, it is going to returna response of dcls other data. And this isa list of the objects in the student model,which is basically all the data in that site.So now, let's save it. And then let's go testour API once again. But this time around,we're just testing we get so get. Don't needto remember to remove this first of all, soit doesn't see no knowledge of it sent. Andas you can see, it doesn't give me a creaseit lists of the data we have in our project.So it gives them in a JSON format. Now ifyou don't see this, this particular scriptAnd then that is just a dictionary. But sincewe see these two ever again, and curly braces,which is not taking each of the data, nowwe know that it's returning it in a JSON format,which is the normal standard way of returningAPI response or request. So that is what wecan do when we're talking about get serializing.Our gets request. But as I said, in Em, Italked about many equals true. But let's sayit's just only one data. How do we do that?So first of all, since we have this queryset, which is all the objects, we know that,oh, God has more than one. So first of all,let's get one, there's only one of the objectsso we can say, student students, one shouldn'tbe equals to queryset dot first. Now, whatthis query said or fails does is that is goingto get the first object in these studentswho do so writing serializer, which studentsserializer. And then we remove many dots true.And voila, passing the query set. Now, we'rejust passing only the first student, whichis student one. So now, we can just returna response or serialize the data. So let'sgo on to sit once again, writing we're gonnaget so once we send, as you can see, justgives us only the first one, the data, wecan easily serialize our data in the Djangorest framework. Now let's talk about authenticationin the Django rest framework. So what do Imean by these authentication? Now, these authenticationis going to allow us to protect our API endpoint.So we might have some API that we can justallow anybody to use without authenticatingor without authorizing that user. That's fine.Boom, I also have some API's, which we wanta user to, first of all be authenticated,I want the user to have an API key or a tokenor something before you can assess that particularAPI. Just for example, we use the YouTubeData API, it needs to provide an API key whichyou get from your Google Cloud account orsomething like that. So that API key is goingto be used to authorize you or want educateyou to be able to use the API. So let's dosomething similar in this tutorial. Firstof all, what we want to do is to come intoour coach, right here. In views, we're gonnause something called permissions, these permissionsis from the rest framework. So if I say fromrest, underscore framework. That's permissions.Import. So when I say the restroom of thepermissions inputs, we are going to get abunch of permissions on bunch of wanted dicationlists. So like I can use allow any. Now thisis quite self explanatory, when clicking allowany just allows any access, this isn't strictlyrequired. But you could use an empty permissionclass list just to be. So what this is justsaying is that you can allow anybody to usethis particular API. So let's also see anotherone like, is authenticated. So you can seewe have is admin user is authenticated, todedicated or read only. So we have a bunchof so is admin user does also say for displayexplanatory doesn't be an admin user beforethe person can access the API, or is authenticated,this is the one we are going to talk about.So the user has to be authenticated into thisapplication. Before we can give the user thechance before you can give the user the wayor something to be able to use our API. Sonow let's import is authenticated. This one.So now that we have that imported, we canuse it in our test view. Plus, to do this,we can just add the code right here. So let'ssay before any of the functions, let's justadd a variable named permission classes. Nowthese permission classes is going to giveus like the permissions we want to collectbefore a user can access any of these. Somost users on dedicated, can anybody justaccess it, mostly be an admin user, whatever.So there's gonna be a tuple. And then we'llsay is authenticated want the user to be authenticated?Let's give it like that. So we only want authenticated.Now if you want allow any damage anybody,you can also just leave it blank like this.This just means that anybody can access it.Or you can just remove that. Anyhow, you wantto do so by using dedicated means the userneeds to be on dedicated before, you can useit. Now let's save it and try something. Ifwe come into postman, and then we just sentis gonna throw us an error. So as you cansee, okay, this is not the arrow we are lookingfor. So this is just saying that our hostis not running. So let's come in here. Soit's running right now. Let's try that again.So it's gonna give us a notification arrow.Good. So it says detail. authentication credentialswere not provided. So now as you can see,it requires us to be authenticated to providesome authentication token or something beforeit can give us access to URLs to our API's.So now to be able to, to set up this authentication,we need to come back into our code. And insettings.pi, we're gonna scroll all the wayto the bottom. On the right here, we're gonnasay wrists. All the scuff free work shouldbe equals to column braces. And then who saiddefaults. I'll just go on to education underscoreclasses. Now, what we need is a square bracket.And then you say rest. Now this should bein small caps, rest, underscore framework.authentication, token, authentication, thisis what we need. And then now we can savethis. So we can create this file. And thennow that we have now to use this rest framework,we also need to actually add something, let'sgo back to that settings to the installedapps. So screw up. And then in the installedapps, we want to add rest framework. So asyou can see, we already have rest frameworkadded on to this rest framework, dots fourth,talking, so that is different. And then we'lljust save it to read for a month or two. Okay,now we can quit it. Before we continue, weneed to run migrations. So let's opt out ofthis server, Python manage. py make migrationsto after making migrations, no changes detected,actually. So they're just wanting to spy migrate.So this is going to migrate to the rest frameworkdot auth token into our database, which Kathyare talking or talking out. Okay. Ledger'sroll our server back. Actually, I don't wantto run the server back. So let's quit it out,I want to do one thing. So first of all, Iwant to flush all the data we have in thisour database. So we can, like show up canshow you how to create a token for each user.So now we still have a user, let's flush everysingle date. So say my UI flush. So this isgoing to flush all the data we have in ourdatabase, just click Yes. And then done. Sonow we don't have any user, if I come in here,I should actually be given an error that I'mnot dedicated or something. So okay, it canrepeat because there's no running. Both Normally,the admin is deleted. Now want to create anothersuper user, a new super user, say python manage.py.Create a super user. So right now, it shouldprompt me to input user name. So user name,leave that blank. Why good? So now we havethat created. Now, let's run our server back.So let's give it So if we come back here nowinto our server, so it asks us to log in again,because we flushed out the data at first.So, logging, good to come to the home, you'regonna see now that I have odd talking up,and they Nandita are talking Moodle. So thisis what we just did. So a good way to createa token for user, one easy way is to justcome into our command line is up to the serveragain, and same Python, manage dot P, y, d,r f, underscore create underscore token, wejust pass in the user name. So this is goingto create a token for whatever user name wepassing. So let's wait for that is going togive us a token right now. And it's also goingto save it in the host. Okay, so as you cansee, it gives us this token, just copy that.And if we come in here, and it's refresh onthis model, we're gonna see that we're gonnahave one object. Okay, so let's first of allrun our server back, before we go test itout, just to make sure everything is working.So now let's hit refresh on this token. Now,you can see now that we have that token righthere, the same thing starts with B and witha C, A, B, and with a C, for the admin userand created and this time, so this is whatwe are, you can easily create a token fora user. Now this user as a token, let me nowshow you how you can use this talking in postman,so you can authenticate. So normally, we'rejust gonna come into our postman to authenticateusing de-stocking, what we just want to donow is to go under authorization. And thenlet me first of all, put this down a littlebit. So the type, we want to change this typeto API key. So it's giving me this becauseI've tested some earlier before. So let mejust show this on step from scratch. So thekey, the default key for Django shouldn'tbe authorization, authorization, and the valueyou're going to write is going to be talkingand then followed by that particular token,which was created for the user just talking,which is tempting as the stalking. So let'sgo back to postman. So right here, now, weneed to make sure that we're adding this tothe Edit notes to query parameters. Let'sbring this up a little bit. And it said, sonow, it doesn't tell us now again, that credentials,tightknit some authorization credentials.As you can see, it gives us a JSON response.It says name is blank age is not all thisis because remember, we flushed our databaseearlier. So that's given us know if we havesomething in our database is obviously goingto show that to us. That's how you can easilyauthorize or authenticate in your Django restframework. Well, now you know that let's sayyou are using an external framework, likeyou want to use react or something in thisyour project, you don't want it to you can'tdo this manually, like I just saw, we hadto come here to type by tomando spy DRF gradetoken admin, before we were able to generatea token for this user. We can't do that foreverybody on our platform, we want it to beautomated. I mean, that is the main purposeof programming, right? So what we are justgoing to do is to send details of the particularuser, so its username and password are goingto send it to our application and is automaticallygoing to generate the token or show us thatokay. So first, we're able to introduce aregonna come into VS code, Amanda URLs A p y,we're gonna say from rest framework.us talking.Here, this one, those of us want to importobtain of talking. So what this is going todo is we don't need to create a new view inviews of UI. So this is a default, built inview, which is from the rest framework thatare talking. So it allows us to just senduser's credentials, and then it obtains theauthentication token for us. So now let'sadd a new path. Let's give a comma, path.And then right here once the API slash talking,slash, and then it'll give you that obtain,or stoking. And then I'll give it a name ofsomething like obtain. So now that we havethat, we can test our API. So first of all,let's copy this. Let's go back to postman,to what wants to do is to open a new tab.And then let's set this to post. And thenlet's give it slash API token. And then righthere are gonna come into body form data. Andthen we're gonna use the key of user nameis going to be the user name, which is admin,and then a key of password. And then thispassword, I'm gonna leave it blank, becauseI don't want to show any password in thisvideo. But once you just put the passwordof that particular user on it st is goingto show you the authentication token for thatuser, basically. So that is how you can dothe magic also access this from your code,you know, you can do something like send ina request to this particular page, and thengetting the authentication token. So thatis how we can easily authenticate a user inDjango rest framework. So I really hope youunderstood everything we did in this video.I hope you go through the concepts of theDjango rest framework. I hope you understoodAPI's or Europe you now know about serializers.I hope you now know about authentication inyour Django rest framework project. So guys,that's going to be all for this rest frameworktutorial. I really hope you enjoyed it. Andif you did, please don't forget to smash thelike button and subscribe.\n"