Django For Beginners - Full Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody and welcome to this django complete course now in this video i'm going to be covering all of the important aspects of django then as a beginner you need to know so from setting up a simple django application to creating a database to having users log in sign up and sign out to having user specific pages that is what is going to be covered in this video now just to make something really clear here this video is a combination of 11 previous videos that i have on my channel currently i decided to re-edit these videos just to have them be a little bit nicer and combine them all into one video because when i posted this series it was probably about a year and a half ago and i have a lot of new subscribers now that probably don't even know i have a django tutorial series so with that said i hope you guys enjoy if you do make sure you leave a like and with that said let's dive in after a quick word from our sponsor we get started i need to thank the sponsor of this video which is alco expert algo expert is the best platform to use from preparing for your software engineering coding interviews and has the highest quality coding interview practice questions with over 140 practice questions detailed solutions in nine of the most popular programming languages a feature-packed browser-based coding environment extensive test suites and conceptual overviews and code walk-throughs for each and every problem algo expert is the best resource to use to ace your coding interviews algo expert also has a data structures crash course coding interview assessments and a mock interviews feature i can highly recommend algoexpert as a former customer myself and now an official instructor on the platform get started using algo expert today by clicking the link in the description and using the code tech with tim for a discount on the platform hey guys and welcome to a new series which is django web development with python now if you haven't heard of django before essentially it's a full stack web framework which allows you to create websites using purely python and a little bit of html now this is really awesome because typically when you want to create websites you got to use a combination of languages you got to use javascript html css all this kind of stuff php but if you already know python this is a really nice and fairly simple way to actually create fully functioning websites and that's what i'm going to be showing you throughout this series now this first video is going to be dedicated to setting up our project understanding a bit about how django works and getting the server kind of running on our local machine and then later in other videos you're going to be working with databases templates making fully functioning websites and hopefully near the end i will work on a large project and show you guys how we can get everything set up to create an actual website that you might be able to use uh so without further ado let's get started now the first thing that we're going to need to do when we're working with django is we need to install it so i'm assuming you already have python installed if you don't you're going to have to go ahead and do that but from there we need to install django to do this we're simply just going to open up our command prompt we can just type cmd in little thing here and you pip uh install and then django like so now i already have this installed so i'm not going to do this but if for some reason when you hit enter and this doesn't work it means it says like pip is not in your path or something like that click on the video that i'm going to have a link there's going to be a card to it and a link in the description it's called how to install pygame but this goes through how to fix this pip issue so just watch through that video and it will explain to you how to fix this issue and when it you type pie game when it says like type pie game just type django instead and that should hopefully fix your problem now for me i'm actually working in a virtual environment uh for django this doesn't really mean anything to you don't worry about it so i'm just going to activate that now but what we're going to do to start our project is we're going to create a directory somewhere accessible that we're going to install all of our kind of django stuff into so i've created one in this kind of directory system here so desktop python youtube django tutorial so i'm just going to change into that directory by using cd so we'll cd into desktop cd python cdut tube and cd django django like that so now i'm in this directory but if you guys don't want to do that or it's a complex path all you can do is open it up your folder here and then type cmd and it'll open up a python or a cmd window that is in this directory like that for you okay so now that we've done that what we need to do is we need to create a brand new django project now to do this what we're going to do is type django hyphen admin and then start project i believe that is and the name of our project which in this case i'm going to call my site now you can name this whatever you want however if you try to name it the name of a python package so maybe like numpy or site or something like that it won't work so if you get that error just try changing the name to something else so i'm going to do that and now you should see inside of my django tutorial folder i have this new directory called my site now if i go in here we'll look through some of the files that we have so we have this manage.pi file inside the root directory of my site and this is what we're going to be using to create applications to run our server to do all kinds of stuff so this is an important file to use and then inside of my site so the other directory we have a few of these files like this i'm not going to go through what all of them do but we will be modifying this url's file later in the video okay so that's a brief overview of what that is so now that we've done that we've actually created a django uh project and we can test to make sure that this project is working uh by just running a uh a server on our local machine that's gonna allow us to connect to our website so right now when all the stuff we're going to be doing is known as development so essentially we're just working on our local machine our website is not live on the internet like not anyone can go to it but when you run this it's going to allow you to connect to it and view it as if it was live on the internet but it's just running off our local machine to do this what we're going to do is we're going to type python or sorry actually one step before that we need to change into this my site directory so right here we're in this directory now we need to go into my site so to do that we're going to go cd my site and now what we're going to do is we're going to run this manage python file with a few arguments so to do this we're going to do python manage if i do space here manage dot pi and then we're going to say run server like that so let's hit enter here and what we're going to do is now we're going to start running a server on our local port which is actually 8080 which is going to allow us to connect and view our website we don't have anything on the website yet but i will show you connecting to it so to connect to this what we're going to do is just copy this http link here looks like a little ip address and we're going to go to google and simply paste that in the uh bar up here so when we do that you should see a page that looks like this if you don't see this page re-watch uh the last few minutes of the video and make sure you follow the steps correctly because you should see this popping up all right so now that we have that we'll leave that open and i'll quickly mention that right now this is running on port 8080. if you for some reason port 8080 is blocked or you want to run it on a different port what you can do is simply when you type that run server command after run server just type the port you want to run it on so for example if i want to run it on port 5050 i don't even know if that's a port but you could just hit enter and then it would run on that port and it would give you a different address to connect to uh the website okay and also if you want to stop the server from running which is what i did i just hit control and c on the keyboard okay so now we've got this uh we'll close this up for now and we'll look at that after what we're going to do now is create what's known as an app now right now we haven't actually created an application or any views or any web pages for our site we've just kind of set up the environment that's going to be hosting that site for us that's kind of a way to think of it so if we want to create an application which is what we're going to run from our kind of environment to do this we need to what do you call it so we're already in this directory we need to use this manage file once again to create that so to do this i'm going to do python and then i'm going to go to manage manage dot pi and then type the name of or sorry start app after this and now type the name of whatever app i want to uh to create so in this case i am just going to type test as my app name but you guys can type whatever you want actually you know what let's change this to main so now that i do this i have python manage.pi start app and then i hit enter like this now you can see that it should create a new directory inside of our my site directory called main now it's very important that it's in this directory if it's not there is other ways to access it but it's not going to work for what i'm going to be showing you so now we should have a directory system that looks like this django tutorial you have a folder called my site you go in there you should have main which has a few files in here which we'll talk about after and then it has my site and this manage dot pipe manage python file okay so now that we've done this let's rerun our server and connect to uh that page so to rerun our server same thing python manage.pi run server and we'll do that we'll copy this link once once more and just run this up here all right so there we go so now everything is is working fine so what we're going to do now is we're going to start modifying some of these python files and actually displaying our own html code on the website now it's a bit of a process make sure you guys are following along for this because there is quite a few steps and if you mess up one slightly uh it will result in a few issues happening in your with your website and connecting and all that so what i'm going to do is i'm going to open up a text editor in this case it's subline you guys can use whatever you want as long as you can edit these files and just understand what i'm doing so i like this just because as the directory system on the left here so i can easily navigate between stuff so what i'm going to do we'll close these up for right now is i'm going to start by going into my main folder and going into this views.pi file so this views file is what's going to actually store the different views for our application now a view you can kind of think of as a web page and this is where we're going to write essentially the code that's going to serve what's known as http requests and show some stuff up on our website now to do this the first step is to just import something which i'm going to say from uh jenggu dot dot http and then response we're going to import uh http response now i believe i probably butchered this yes sorry so it's actually just django.http um is that correct lowercase h my bad guys so drango.htdp import http response now down here we're going to create a function and this function is going to represent a view now we can create multiple views here but for now we're just going to stick with one and i'll be showing later on how we can connect different views and link to those and all that so we're inside define index we're going to put in here response and then what we're going to do is we're simply going to return http response and in here we're just going to type some text now you can type whatever you want i'm just going to say tech with tim in here and this is actually our first view now what goes in here is html code if you don't put any tags so for example like i don't put h1 um slash h1 it'll just show up as like standard text but if you want to create a header or something you can just do h1 and i'll be talking about how to do more complex html stuff later so that should be it for this file right now and what we're going to do next is we actually need to create a new file inside of this main application that's going to represent our urls and we'll talk about how all this works in a second so i'm just going to create create a new file here so file new file and what i'm going to do is just make sure i save this and i'm going to call it urls.pi but it has to be inside of this main folder so it should be in here okay so urls.pi now in here is where we're going to define the paths to our different web pages and once we do the other there's another url file we have to modify as well but this one is going to represent the urls that go to the different views that we have in this file so for example right now we have one view but if we had another view so like if i copy this and paste this down here then we would have to define that inside of the urls file with a certain path so we can determine which view we're going to go to uh based on whatever path the user types in uh in the search bar at the top okay so we'll go urls.pi and what we're going to do in here is we're going to say from django dot urls import path like that okay and then in here we're going to say from dot views or sorry from dot import views now this essentially means just import views from the current like directory that we're in uh so that's how we'll do that and then in here we're gonna type url and here what we'll do is simply say path and then we'll put a comma after that and we're just gonna type um a blank string and we're going to type views dot index and then name equals index like that now what this is going to do uh we'll talk about this more later because we have to do some other stuff first is essentially say if we get into this application and we're just on the home page so we don't type like slash home or just the home directory we're going to go to the views.index page and that has the name of index and what that means here is we're gonna serve this http response which means that once we go to that page it should show uh tech with tim in a header one on the page now this will make more sense once we do the other url file and i can show you how we kind of navigate through it but for now uh just just have this typed in so that's actually all we have to do from inside of this main folder now what we have to do is we have to link this application to our project now remember this this django tutorial folder right is the project for our website and this main folder inside here is the application that we're going to link to our project it's a little bit confusing but you guys should understand in a second so what we need to do is we need to essentially set the url that's going to link to this application because we can have more than one application inside of our project so to do this what i'm going to do is go to the url files inside my site and this should actually already be created for you you should already have this code and i'm simply going to modify this right here so from django.urls import path and import include now after this path here i'm going to copy this and paste this directly below it now what i'm going to do is i'm going to say that i want to navigate to this application when the user types in a certain path and what i mean by path is let's go up here right now we have this okay but when i say path i mean like if you type slash home the path would be slash home right and we would have to know where to go if you type slash home just like if you go on a website and you do slash login or slash sign up you get directed to different pages so that's what we're doing right now so maybe we have another page it's called sign up or something like that so we have to define when we type certain paths where we're going to go and that's what we're doing right now so we already have one path which is known as admin now admin gives you like an admin dashboard and we'll look at that in later videos right now it's not super important but we want to define the path that we should go to automatically when we type something so right now i'm actually just going to leave this as blank and what this means is if we don't type anything so we just put in this main url bring us to whatever page i'm about to define here so in here i'm going to type include like this and then what i'm going to do is in strings here i'm going to go to main dot views i believe actually sorry main dot urls is the correct page there so what this means now is if we don't type anything for our path we will automatically direct ourselves to the main.urls file now the main.urls file is this one right here and what it's doing here is it's going to look at what path we've been given we'll talk about that in a second and then go to the appropriate view from this views file here okay so it's we're linking from multiple different files we're sending paths and all that stuff okay but if we look at the urls.pi file here under my site what this include actually does is it means okay we're going to look for a path that specifies whatever's in this string so in this case it'd be admin in this case it's nothing it's just the default path and what we're going to do is we're going to take everything after that path and we're going to send it to the main.urls page so for example if our path and i'll type it down here looks like whatever the ip address is and then like slash home slash start and we had slash home here okay what we would do or we'll do home slash like that sorry is we're gonna look for the this home path here so we find this we find home okay and once we find this what we're gonna do is we're gonna say okay so we'll get rid of this because we found that and we'll take start like that and we'll pass it over to this urls.pi file inside of our main application because it says go to main urls right and now what main urls is going to do is it's going to look for a path that's called start because it gets past start like this and it's going to see okay do i have any path that says start now if it does it's going to direct us to whatever function inside the views file that we've defined so if i add another path here okay and i define this and i say this is start with a forward slash so let's say that has a forward slash two then what will happen is we will go to the views.index view because that's the path that we typed in now in this case uh we're just going to leave it as a blank path which means that if you had nothing just like that it'll just automatically go to this path you guys should understand this in a second once we start actually doing it okay so we've done this now so actually i don't know if we're going to have to restart the server or not but let's just hit enter one more time in the search bar and see what we get okay so we get now tech with tim in the header one tags now i know i kind of went a little bit faster this and it might be a little bit hard to understand but we'll create another page now and i'll show you how this actually is working so um we've done that let's leave this open so essentially right this is what was shown we had inside this views.pi file we had this index function and it returned h1 tags tech with tim now what i'm going to do is just create another function i'm going to copy this and i'm just going to call this let's say v1 okay and then here instead of tech with tim we'll just say view one exclamation point okay so now let's show how we could possibly navigate into a different view using this kind of url structure that we've set up so remember this urls inside of my site defines what's going to happen when we go to a certain link what page we're going to direct into so i had this as blank before so what happens is if you don't type anything after the main url which is like that https it's just going to direct us to the main.urls and it's going to include whatever comes after this blank tag essentially okay so if we want to make it so we could possibly go into another uh what do you call it file folder whatever another view what we can do is add another url inside of this urls.pi so i'll copy this path and instead of having a blank this time i'm going to say slash v1 or i'm going to say sorry v1 forward slash and now instead of going to the views.index view i'm going to go to views.v1 remember the name of our function and again i'll call this a different name which will be view1 all right so that hopefully this will make sense if we don't type anything so meaning we like we don't type admin what's going to happen is whatever the path that we've given is going to be passed over to this urls.pi file if it's blank meaning we haven't typed anything at all other than the main url it's going to bring us to the index page if we type v1 it's going to bring us to the v1 page so let's try this on our web browser if i change this now and i say slash v1 you can see that it brings me to the page v1 now remember if i get rid of v1 and i hit enter it brings me back to the page tech with tim so we successfully set up two pages that we can see and we kind of understand now how this url directory system works so that's all it is um to setting up our basic django pages uh in the next video we'll do a bit more on some multiple pages we'll talk about creating some actual like real html stuff on the website uh and just keep going further and further with django if you guys enjoyed the video please make sure you leave a like and subscribe if you need any help uh don't hesitate to join my discord server follow me on twitter or my instagram i'm always answering people's questions there and with that being said i will see you in the next so in today's video what we're going to be doing is going through databases so how to set up databases add entries retrieve entries all that kind of stuff this will be kind of a beginner-ish tutorial on databases i'm not going to be going through absolutely everything as there's a ton of stuff to cover but i will give you guys a very good foundation and pretty much everything you actually need to be able to use the database then obviously you could probably look up some more stuff if you need that in the future now the database that we will be using is sqlite3 now there is other kinds of databases that you can use but if you're a beginner and for our purposes sqlite is just the best and easiest to use it doesn't really make a massive difference if you use the other ones however if you'd like to use those go ahead and i will be showing you briefly how you can actually change your database now the reason i'm not going into templates and more advanced html right now is because likely the information that we're storing in our database is actually what we're going to be wanting to show within our models uh or sorry not models within our templates and html so it kind of makes sense to make the information first and then display it afterwards within templates and all that so we're not uh kind of redundantly typing things and modifying things later so with that being said let's get started now our first step when we're gonna be working with the database is we actually need to modify uh our settings.pi file inside of our interior my site directory now to do this obviously we're going to go to settings.pi what we need to do is need to scroll down to install apps we need to add our application in this case called main for me to our installed apps and the reason we need to do this is because we're going to be working with databases and just some things in the future we need to tell django that we have another application that has some dependencies and things that need to be set up inside of our project so to do this what we're going to do is just go single quotes right at the end of this uh what do you call it wherever the comma is and we're just going to type the name of our application in this case mine's called main yours this might be called something else and then we're going to type dot apps dot and then main config and then add a comma after that now obviously if yours is named something else you're going to change this so you'd add a capital letter for whatever the name is and then yeah just put it there and that'll work for you okay so we've done that and now we've told django that we actually have this application main and we need it to be configured and set up when we uh make some modifications to our project and stuff like that so our next the next thing that we actually have to do is we need to get into our my site directory so the same directory that has that manage.pi file in it and we have to run the following command which is python manage.pi and then migrate now when you type this uh what do you call it yours might yours should likely pop up like a bunch of text that says making migrations making changes now since i've already done this because i was testing it before it's not showing up for me but you should do that what i've just done here essentially is that we've updated the settings.pi file so let's run manage.pi and get it to make any changes to the project that it might need to do and that's as far as i'm kind of going to explain that all right so we've done that and now we're actually ready to start defining some of our models for our database so if you don't know how to a database works essentially it's just a collection of information and what we're going to be doing is defining some models and some attributes that kind of go with each of the models and the model is just a way of well modeling information and it makes it just easier for us to grab information and we can add attributes to those models we can add some methods to them you guys will see how it works in just a second but essentially if we want to create a model what we're going to do is we're just going to create a class with the name of our model and we're going to inherit it from models.model which is like a database model class set up from django already now for this application that i'm going to write i want to create a to-do list so to do this i'm going to create two models one which is a to-do list and then the other one which is items that go on our to-do list and you guys will see how this works in a second so i'm just going to say class to-do list like this and it is going to inherit from models dot model now this essentially means that we're creating a database object uh which is called to-do list and now we're going to define some of the attributes and entries that each model to-do list is going to have so uh for our to-do list i want to have a name so i'm going to say name is equal to and in this case models dot chart field and i'm going to say max underscore length equals 200. now whenever we create a new attribute or uh yeah i guess just attribute of our information of our model what we do is we create it as a class variable and we simply do the name of the attribute and then we have to do the type of field that we want to be stored in our database all right guys i'm back so i'll take a quick cut there because it's getting a phone call but what i'm going to do now is just define a method uh we'll just call this str and i'm just going to put self in here and simply return self.name just so that if we ever want to print this out or see what it actually looks like we can get some meaningful text by using the string method on that so next what we're going to do is define our other model which is item so same as before this will inherit from model stop model and this is going to have some attributes as well now item is a little bit different just because it's actually related to to-do list and we're going to have items as a part of our to-do list so to do this again right what we're going to do is simply say to do list equals and in this case we'll say models dot foreign key and then in here we're going to type to do list like that and we're going to say on delete equals models dot cascade now the reason we're doing this is because remember how like up here we have character field right which is a type of field that we could store uh information in well we don't actually know the type of fielder django doesn't know the type of field that to-do list is because it's an object that's not defined within django so we have to define the fact that we're going to use a foreign key in this case a to-do list object when we create an item okay and that's what we're doing now on delete is just saying well if we delete to-do list since all items exist on a to-do list we're gonna have to delete these as well and i believe that's what on cascade is doing is just defining the fact that this has a special way of being removed okay so our next attribute is going to be name so i'm going to say sorry not name it'll be text and text is going to be equal to a character field as well and a character field is essentially just a string note that you do need this max length whenever you create a character string so make sure you add that in this case let's just make that 300 and now we will add one more field which will be a boolean field so models dot boolean field and it'll just represent whether or not we've completed the item on our to-do list same thing here for string so self and we'll just return the text so return self dot text now remember in the future we can add to these models and modify them so for now i'm just keeping it simple we don't need anything too complex all right so now that we've done that we've modified our models we actually have to tell django that we've modified our models and to do that what we're going to do is we're going to make sure we're in that same directory so my site i'm going to say python manage dot pi make migrations in this case we'll put the name of our app which is main now uh yes that's okay so this should work and let's hit enter here and see what we get all right so there we go so now when you do that you should see something that says migrations4 and then the name of your app which should be main it says we created a model to do list and we create a model item now making migrations is similar to like adding something to the staging area and git if you don't know what this is don't worry but it's similar to version control in that we make a change it'll save the change and then we can actually apply that change to our project so if i want to apply this change right now i've only made it i haven't actually applied it what i have to do is go python manage.pi and then migrate and there we go it says applying migrations and it has applied the migrations you should see if you go inside of your migrations folder inside of your app you should get something that looks like this and you can see if you actually open it up it tells you the exact migrations or changes that were made in case we have id uh id is automatically added for all of the different models that you create as a field we have the name which is a character field we have text complete and to-do list there we go so um that's kind of how that works it's nice because you can go back and view previous changes and then obviously revert to other changes by just using those files uh so yeah all right so now that we've done that what's actually next is to add some things into our database so right now we have a fully functioning database and i'm going to show you how we can add stuff to it now the easiest way to show you is just from the command line because we'll just mess around with a few different commands get the syntax down and then start doing stuff from code so to get into a command line what i'm going to do is just go python manage.pi and then shell this will open up our python shell for us which will allow me to add some things into the database now our first step is we're just going to import our models so we can use some of the methods and we can actually use those models to create objects and store them in the database so i'm going to say from and in this case main.models because we're not in that main directory we'll import what's the name of our models we have item and we have to do list like this there we are so from main.models import item and to-do list and now what we're going to do is we're going to create a to-do list and add it to the database and this is really easy to do so i'm just going to say t which is going to be our to-do list will be to do list and then in here i'm just going to give it a name and i'll say name equals in this case let's just say tim's like that list suite so tim's list and hit enter now if we want to save this into the database watch how easy this is t.save and we have actually now saved this into the database and if i want to see all of the different objects what i can do is i can say to do list if i can get the capitalization correct dot objects dot all and if i do that you can see we get a query set and it says to-do list tim's list and there we go we've successfully stored one to-do list in our database so to get all of the to-do lists that we have i just did objects.all and obviously dot objects is giving other objects and dot all is actually going to give me like a query set which will allow me to access objects now each of our objects have ids associated with them and they have that name attribute associated with them so if i want to see the id of some of my objects what i can do is say to do list and i believe i can say dot get and then in here i'm going to say id equals and then in this case the id is going to start at 1 and it's going to increment as you add more objects but if i do that type object to the list has no attribute get oh i believe we might have to do objects.get dot objects.get ah there we go so if i do objects.get and i put the id which is the thing that i'm looking for id1 you see we get a to-do list and it says tim's list now if we didn't put that string thing here string method inside of to-do list it wouldn't be saying tim's list it would be giving us like a memory address awesome so we have that now if we want to query by like names what this is doing querying just means like getting all of the objects that contain the key you're putting what i can do is just say name equals in this case and say tim's list like that and obviously it's going to give me tim's list now if i try to query for something that's not that doesn't exist like i say id equals two you see we get an issue because there's no query that exists for id2 if i wanted that to work i would have to add another item into the database suite so that's kind of how you do some of that now if we want to create an item what we can do for items is actually really nice is we can just let's see the best way to actually make an item is let's see this we're going to do t dot and in this case we're going to say item underscore set and if i print this out dot all like this you're going to see we get an empty query set now notice i did item underscore set right which would be um an attribute of our to-do list uh t right because we created two lists here we saved it and so the t object is still there but i said item underscore set but i haven't defined item underscore set in here what this is is because i've added this relation between items and to-do list each to-do list automatically is going to have a set that stores a bunch of different items okay so now the way that we add items into our database is a little bit different than how we create the to-do list now because our items are related to our to-do list there's a special way that we can create them and create them within our to-do list so essentially remember we have that to-do list t i just tab down just a bit more space and it's cleaner but uh we have that object t and if i printed that you can see that's our to-do list tim's list now because of the relationship we've created here what i can actually do is say tim underscore and then item underscore set dot all and it actually gives me a set of items which are exactly these items and you just reference all of this with automatically with a lowercase it's what it defaults to and yeah so essentially there is like a blank placeholder for our to-do list to hold a bunch of items because of what we did here so if we want to create an item inside of this item set what we do is we say t dot item underscore set dot create and then here we give the parameters that we need for our item so we need a text and we need complete so what we'll do is we'll say text equals and in this case we'll just say like maybe go to the mall something you have to do and complete obviously will be equal to false okay so we do that and now we see we have an item that says go to the mall so we've done that now we've created an item inside of our item set now if i do t dot item underscore set and then dot all you can see that we get all of the items and obviously if i want to get one of the items and i can say dot get and in this case it'll be id1 so i say id1 go to the mall again if i try to do id2 we're going to run into an issue because id2 does not exist all right so now that we've created uh one item or we've created an item in a to-do list inside of our database what we can do is we can actually display that information from some of our views and start using the web browser to see this information so the reason i did that from the command line is just because it was a lot it's gonna be a lot faster just to run that and actually add items to our database obviously if we're adding things into our database in future videos we're probably just gonna use our web browser and we'll have like a form where we can input stuff and it'll automatically be added and that's obviously what we'll be doing later so what i'm going to do is i'm going to go to my views now and i'm actually just going to get rid of u1 which means that if i go to urls i should remove the path v1 now what i want to do is i want you to be able to type the id of a certain to-do list in the address bar and it pop-up the name of the to-do list and the items that exist in that so to do that uh i will briefly show a cool thing that we can do with paths and we'll elaborate on it in future videos but essentially i can actually put these two tags in here and say int and in this case i'll just say ind or id standing for id and what this means now is what's going to happen is we're going to look for some integer in our path and we're going to pass that to the function views.index so that means that index now needs a variable called id in it and what i can do is i'll show you basically without the database actually is if i just put like percent id and then or percent s sorry and then outside here i do percent sign id it will actually what do you call it show me whatever number i type in in my what do you call it like on my web browser uh so i closed the command prompt i shouldn't have done that wow one second i just got a cd into my correct directories here django cd my site and then we will just simply run our server so we can test this and i can show you what i mean so let's do python manage.pi run server i gotta activate my virtual environment apologize about this guys okay so there we go so we've got this running now so let's go to our web browser and let me show you what i mean by this so if i hit this now you can see we get an issue because it says that it didn't find admin or it didn't find some integer which was an id so now if i type one in here it's like slash one you can see it actually brings me to a page that says one and if i type 3 in here brings it to a page says 3 if i type 4 we get 4 and actually anything that we type in that's a number will just show up in here so we do like 4 8 like it shows up there okay that's like the first kind of way that we can do dynamic pages in terms of the linking all right so what i'm going to do now is i have this id obviously so i don't want to just show the id but i want to get the id of that object as a to-do list from our database so to do that what i'm going to do is similar to what i've shown you in the command line is i'm start i'm going to start by importing our models so in this case i can just say from dot models import and in this case we'll just import to do list because actually we might need item as well so we'll import item as well so we'll do to-do list and item and what i'm going to do is get that to-do list based on the id so i'm going to say that i'll say ls is equal to to do lists dot objects dot get and then in this case we'll say id equals id right so now we have that to-do list object and now instead of printing the id let's print uh what he called the name of our to-do list so i can just say ls dot name so now we should have made a modification and it should have just our server is running it should just automatically changed let me just copy this link again and if i bring up my tab uh oh it's already there so if we do this and just change this id to 1 now you can see that we actually get tim's list because again the way this works is we go to urls we type some number it gets that number it passes it through this function as the value id we're just going to say we're going to go the similar thing we did in the command line well to-do list we'll get all the objects of type to-do list we'll get the one that has id1 and then we will simply take the name of that and print it to the screen or show it on the screen now again i can change this from id and i can make it name and i can make the name like tim's list so you'd have to type that in to get it so i mean we can show that as well so in this case let's just do string and then we'll do name and now we'll just have to make sure that when we type it in our link bar here that we actually type everything correctly and make sure i save all this too we type the name exactly like this so if i copy that and i put this here you can see that again it's showing up tim's list and we're not running into any issues but if i try to do like two here you can see that we're getting an issue because there's nothing with the name two in our database awesome so that's pretty straightforward that's how we get items and show them on the screen in the next video we'll do way more advanced stuff with this but if i want to get the items that are associated with the to-do list and show those as well well what i can do is uh well let's go back to uh no we'll just leave it as name so we don't need to change it now we'll get the items so to get the items we're going to say items equals and then in this case to-do list or actually ls because we've already got the to-do list dot item underscore set and then dot all and then what we can do is we well we know we only have one item so let's just get the first item so yes we just do dot get and then id equals one and we'll do is change this percent we'll add another one and we'll simply say item dot name or items not name i guess ah this should probably just be item let's say item.name or dot text my apologies okay so now that we have item.txt here we to add another percent in here so i'm just going to put another tag i'm just going to say br and then what do you call it br just standing for go to the next line and we'll add another tag this case is just going to be a p tag and we'll just put percent s like that so now if i go back to my bar here and instead of doing t i do tim's list and i hit enter what's the issue all right so i just realized we actually have to just put this string around item.txt don't know why that is but apparently that was the issue so anyways now if i go back to my web browser and refresh you can see we say we get go to them all now obviously it's a very basic example i'm going to make this look a lot better in next videos and we're not going to have to do like this kind of weird html tagging and whatnot but that's kind of been it for this video i hope you guys have an idea on how to use databases we'll be continually using them adding things and removing things and all that kind of stuff so if you are still confused we will be going through that in future videos but i just want to make sure we get everything set up and working for right now and with that being said i will see you guys in the next video now today's video is going to be a bit shorter and all i'm going to be doing is showing you guys how to use the django admin dashboard this relates directly to databases and how you can see all of your different tables and entries and all of that i'm going to be quickly showing you a few more things you can do with databases in terms of how to delete stuff and how to get um like lists of entries so for example say you wanted to sort all of the entries or say you wanted to get all of the entries that started with a certain letter or something i'll show you how to do that this is known as querying and there's a ton of different commands for querying so i'm not going to be showing you all of them but i'm sure you guys can look them up or we'll probably be using them throughout the series so you will learn them now i'm in my main directory right now my my site directory the first thing i'm going to do is just quickly extend what i did in the last video and show you how you can get a list of different entries and add more than one because this will be good when we go in the admin dashboard to see more than one entry so i'm just going to do python manage dot pi and then shell and what i'm going to do in here is again import uh what he called our model so from main.models import and then here we'll do item and we'll do two to do list like that and now what we're going to do is i'm going to get all of the items in to do list and show you how we can kind of search for certain items so i'm just going to say t equals to do list dot objects objects.all like that or actually let's just do dot objects so now we don't have to keep typing that we can just type t when we want to say for example get all of the objects we can just do t.all like that and then we get a query set that gives us all the objects but let's say we want to search for an object and before we knew how to get one using like the id equal to one but what if we want to get all of the objects in our set that start with the letter t or that start with tim or something like that well there's a way to do that and it's known as filtering so if we want to filter our query set and get all of the objects or all the data that fits a specific criteria we can say t dot filter and then we can name the criteria so in this case i could say name and then i believe you can just do under underscore starts with equals and in this case tim so there's a ton like there's a ton of these double underscore things that you can use i don't know all of them you'd have to look them up to get them all but if i do this and i hit enter you can see that we get the same set because obviously this starts with tim now if i do this again and i say like maybe bob you see we get an empty query set and this is a way that you can check if a specific element you're looking for is in the set rather than trying to get it and raising an exception so for example if i want to get something that has id equal to 2 and i filter that rather than getting an error we just get an empty query set because none of the ids are equal to 2 right so that's how we can kind of check if uh what we're looking for actually exists in the database so that's how you get stuff now to delete stuff is pretty straightforward you just have to actually get that database object first so i'm going to say dell underscore object is equal to and in this case we'll say t dot get id equals one now if i want to delete this very simple we'll just do dell underscore object dot delete like that and if you hit enter we will delete this object so now if i type t again um sorry t.all you can see that we have an empty query set because we've obviously deleted the to-do list that we've added so let's just create two more to-do lists really simply and we'll just say t t1 equals to do list like this and we'll just say name equals first list and then we'll do t1.save and then we'll do the same thing here with uh what do you call it t2 and we'll just call it second list just so this way when i start doing the admin dashboard stuff which will be in one second then we'll be able to see more than one entry so we'll say second list and then t2 dot save like so won't bother any adding any items that's actually it if you need to get out of this you can just type quit like that and there we go all right so now we've added some things into our database so let's go to our admin dashboard now so how do we do that well our first step to accessing the admin dashboard is to create a login account so right now if we actually run our server and we say python manage.pi run server server will start running we can copy this domain here and we can go to it now remember we actually have this directory or link which is slash admin and when i do this it actually brings me to this django admin dashboard the thing is though what username and what password should we use well we don't have any so we need to actually create one so i'm going to stop running this for a second and what i'm going to do is create a login so i'm going to say python manage.pi and then i believe it is create super user yeah it is so there we go create super user and then in this case what we'll do is just give a username email and password so i'm going to put tim as my username i'll say tim at tech with tim.net and then for a password i'll just do one two three four for now all right uh password is too short okay okay so i'll just use another password then um what is it what is it saying here bypass password okay so it just said that's fine i can use that as a password anyways let's uh now try to sign into our admin dashboard and actually see what we're getting so let's say tim and then my password and click log in and you oh well it would help if i ran the server my apologies on that let's run that and now let's refresh this continue and there we go we are now inside of our admin dashboard now we have these groups in this users database which is actually storing if i go to users and the users that we just created so tim for example right and that's one database that's there same for groups this this is a bit different we don't need anything for that now the thing is where's our other database we created that database and we've been using it that has our to-do list in it well we actually need to give the dashboard kind of access to that database this is really easy to do but i'm just going to open up my subline text again here and what we need to do to do this is go to what do you call it our i believe it is admin dot pi inside of what do you call it the main application folder here all right so we just have to start start by importing our models so from models import and in this case we can just import the model that we care about in this case which is to-do list because items are going to be stored within a to-do list and then we just do admin dot site dot register and then in this case we do to do list which means that now we will actually be able to see the to-do list on our admin site uh so that's that's all we have to do for that so now this should actually automatically have updated but it may not have yeah it did not so let's just rerun our server quickly oh there we go it says reloading okay so now this should hopefully be updated if i refresh this work work work uh i guess not okay so let's just try this again slash admin okay so there we go sorry i've just i've been messed around so now i'm back slash admin and now you can see that under main which is our application main we have the database and model to-do list so if i open this you can see that we have first list and second list now this is a quick way as well if you want to change elements or delete stuff you can go in here and obviously you can just click delete or you could save stuff you can see the history of it and all that kind of stuff so that's kind of how the admin dashboard works in terms of viewing your databases i figured i would just quickly show this to you guys because it's a really useful tool to make sure that what you're doing is actually working properly but remember if you create a new application or you're creating a new model you have to actually add that and register it from within your admin.pi file inside of your application so if i wanted to add the items for example then i would have to do item the item model and i would have to import item so let's just try that quickly and make sure everything's working with that wait for this to uh refresh here if i do this let's go refresh all right maybe we'll just end it and then reload oh and all right it says reloaded so let's try this i go here and i refresh this now you can see we have items and if i go to items obviously there's nothing because we don't have any items so anyways that's been the admin dashboard in the next video we're going to go into templates which will be a much longer video on dynamically showing these kind of this information on our website so today's video what we're going to be doing is covering templates so templates are essentially a way to make your html actually look good and display it on the screen they're really nice in django because you can actually put your own python code and you can pass variables through to your templates which means that you can make dynamic html which will change based upon whatever you pass to it which is really nice so it's a really easy way to connect your kind of back end with your front end and that's one of the reasons why a lot of people obviously love django is because of the fact that you can do stuff like this now i just want to quickly go over what i'm going to be doing in the rest of the series for some of you that were asking i have plans to make a video on how to add a proper sidebar to your website how to do forms because forms are actually their own thing that are kind of complicated in django but i want to do a whole tutorial on that i want to do user registrations like login register sending emails all that kind of stuff and then obviously near the end of the series we'll get into more videos longer videos where i'm not just doing features but i'm kind of working on development of the website and actually probably hosting it using heroku or something like that and showing you guys how to actually deploy this and hopefully for free online so if you guys are excited about that please make sure you're leaving a like on the video and letting me know in the comments and with that being said let's get started with templates now if you remember where we left off we had it so essentially we could view different parts or different to-do lists from our database by typing the integer into our bar and that's really all that we had now what i'm going to do in this video is create templates which will allow us to see our to-do list on the screen in somewhat of a nice form and in future videos i'll add bootstrap onto the website and start doing some custom css classes and stuff but for now we're just going to use plain html and then we'll design and style it all after because styling is really a pain and it takes a long time so the first thing i'm going to do is i want to create a home page for my website so right now we have this um this page where you type a number you can see it but we don't have any home page so let's do that first so i'm going to add a link here which is just a blank string and i'm going to do views dot home and name equals home like this and then inside of our views file here so views.pi i'll create a new function called home so define home and then we'll have response and we don't have any variables so that's fine and in here i'm just going to pass for right now as we're not finished coding that yet okay so templates so right now what we've been doing is we've been uh passing http response to our views so that's the way that we're literally putting the html in here like you can see the tags right now this is obviously not an efficient and not scalable way to make a website so what we're going to do is write our own html files and then we're going to load them up from here actually render them and display them to the screen so that's what we have to do first so the first step to do that is actually create a directory called templates inside of our application directory so inside of main here i'm going to go to new folder and call this templates like so so if we go in main now i got this folder called templates and now inside of this folder templates i'm going to create a new folder called main okay now this might seem kind of weird how we have main and we have templates and we have main but it just the way the jangle works it's really weird i don't really want to explain it is you just need a folder inside here with the same name as your application to load the templates so that's what we're going to do so now inside of this folder is where we're going to put our actual html files so let's create a new file and let's just start coding some html and i'll talk about what this is going to be compared to our other templates so let's just set up an html document here html and you know let's save this as base dot html and we'll talk about why i'm calling this base in just a minute so in here now i'm going to add some head tags uh like that and then we add some body tags like that so inside of our head we'll simply just start by adding a title we will be adding a lot of other stuff into this later in the video but for now we're just going to keep it nice and simple for demonstration purposes so i'm just going to call this tim's website and then inside of my body tags i'm just going to create a paragraph tag and we'll just call this base template okay so that's all we're going to do for now inside of that template and let's create one more template inside of here and this one we're going to call home okay so if i save this and i say home dot html like that and hit enter then in here i'm going to talk now about template inheritance so a really nice thing with django that makes building websites super scalable is they have something called template inheritance now right now i've created this template and i've called it base.html and what i want this template to be is well the base or the standard layout of every single one of my web pages so for example okay so let's just go to uh instagram or something and i can show you what i mean by a base template uh in terms of this so for example a base template for instagram is this like bar up at the top like every page you go to has this at least on the website right it has this instagram it has a search bar and then it has these icons and then obviously it's going to be different depending on what page you are or what account you're on what it's going to show but the base template would be like this top aspect okay so what i want to do is create a base template which will have something that will be on all of my web page so for example on my actual website if i go to techwithtim.net you can see that this up at the top here this bar would be and actually what do you call it this logo thing as well is the base template it's on every single page so what i want to do is make sure that i don't have to actually code that in to each html file that i make because think about it if you have like hundreds of html files i don't want to have to code in that menu bar every time so what we're going to do is we're going to code all the stuff we want in always on the website in what's known as a base template and then we're going to inherit that template with just one line of code from all of our other templates this one's our base and this is going to show up on all of the pages unless we override it from the child templates so to actually inherit this base template what we do is we use the kind of the django syntax here which is we open and close a curly brace it and then we put two percent signs like this and inside of here we type extends and then we're going to actually put in single quotes main slash and then in this case base dot html now we just need to include main here because inside the main folder and what this means is just like in java extending a class you're going to extend this template essentially take everything from this template and use it here now you're going to say well how do i change stuff in here well we're going to get to that in a second but let's demonstrate this first so now that we've done that what we need to do is actually render and use these templates so i've got to go back into views here and right now you can see that all we're doing is returning this http response so what i need to actually do is render my templates so to do that i'm going to remove http response we're actually not going to use that anymore we're going to use the keyword render and then here we're going to put response which lines up with this parameter here we're going to put the template location so in this case main slash and we'll do base.html for this one okay and then we'll do a comma and we're going to put a open dictionary okay now i'll talk about this dictionary more later but for now it's uh we're just going to leave it blank now we're going to copy this return i'm going to do the same thing in home except instead of base i'm going to do home.html and that's actually going to be all we need to do to show these html templates that i've created it's pretty straightforward to do this so now obviously i'm going to have to run my site so let's i got to activate my virtual environment one second here and we'll just do python manage dot pi run server okay so i didn't make any mistakes it doesn't seem like so let's load up google here and let's hit enter and now you can see that we've directed to the home page and we get base template okay now so let's see how this worked so when we went in urls we didn't type any number so we were past just that empty string so what we did is we navigated to the home page so the home page is right here this is the function and what it does is it renders this home.html file so now we go to home.html and in here we can see that we're extending the base.html file which means we're going to use everything from that so what we do is we go to base.html we say okay this is what base.html looks like let's use that and then it uses that and we get base.html so now let's try using for example one now before when we used one what happened was we saw the to-do list and the item now we're not going to see that because we haven't programmed that into our html but just notice what happens when i type slash one uh query does not exist okay of course it doesn't exist anyways just pretend like that popped up i'm now i'm frustrated why that didn't work because we the to-do list there's no to-do list that has id1 apparently um that's interesting let's try two or something and see if that works or zero because this should really be giving us something two there we go okay two so apparently the object we have in there has id2 so anyways now that we have some object we have id2 you can see that again it's showing this base template because we're rendering the base.html template from our index view and when we went to urls we typed some number so we went to index and we passed in the id as that number that we typed into the address bar perfect that is literally how templates work in terms of rendering them now it's time to show how we can make some dynamic templates that i'll actually change based on what you're typing so obviously right now so this one's rendering our base.html this one's rendering home.html in previously we had passed through some value which was our to-do list name and we displayed that on the screen so how can we do that now using templates well inside of our templates so this is base.html what we can actually do is we can use some variables that are passed from views and we can display those in our html so for example rather than putting base template here say i wanted the base template to show uh all of our what do you call it sorry our different to-do list then what we can actually do in here is we can put two so we can of these so open and close curly braces to them and inside here we can type a variable name and then we will pass that variable in from our views so for example if i want the to-do list name maybe i'll pass that in as the variable name so i'm going to put name here now what this means is we're going to be using a variable called name now what i need to do is i go inside views.pi and i say okay so we're using a variable name we need to give that variable to our view to do that we use these right here this dictionary so we are going to type the corresponding name so name here to what we've typed in our html and then we're going to do a colon and put the value that we want to pass whoa what just happened with my lights one second guys sorry something just happened okay anyways um now what we're gonna do is we're gonna do ls.name so we're gonna say the variable name inside of our base.html corresponds to ls name now because we've done that there we're going to run into an issue in our home one because we're looking for some variable name inside our base html but inside our home html file we're extending base which means we need to pass that variable as well so for right now this obviously is not ideal we're going to change this in a second i'm just going to put name and then in this case i'll just say test just so that we actually get something that's working but let's try this out now and see if everything is the same so if i run this now you can see that instead of showing me nothing or showing the base template it's showing me first list which is the name of our first list and if i go to the home page you can see that we just get tests because that's what we've passed in as a variable so that's really the easy way to pass variables is through this dictionary here and it's nice because you don't actually have to type the dictionary here like you can make like my underscore dict equals and then you can update it with a for loop or you can pass a ton of different stuff into this dictionary and then just put for example my underscore dict here and it'll work the exact same way okay so now we've done that we've kind of understood how this works now let's go back in templates and talk about some more advanced stuff that we can do so for example ideally we've kind of messed this up a little bit because inside of our base html we're displaying um what do you call it the name of our to-do list we probably don't want to do that because on our home page we probably want to say something else right or we just our base page probably shouldn't do that so what i'm actually going to do inside here is i'm going to set up what's known as a content block which can be over overrode from other templates and you'll see how this works in a second so if i just do my two percent signs here i'm going to type the word block and then give it a name so in this case i well i won't do name i'll do block content and then what i'm going to do under here is i'm going to do two signs like this and i'm going to say block uh or sorry end block okay now just for good practice i will put this inside of a div so i'm just going to say div and i'll say id equals in this case uh content and then name equals content just in case i want to reference this later we'll do that and we'll just end the div here so tab that in and now what i'm able to do actually is from inside my other templates that extend this template i can pick what's going to go inside of this block so for example the web title is always going to be the same but if i want to put something specific inside here depending on what web page you're on i can do that from other templates so on home for example i probably want to say like home page or something like that so to do this i'm going to do a very similar thing to what i've done here i'm literally just going to type the same thing i'm going to say block content okay and then i'm going to close the block like this by saying end block and inside here i'm going to put a parrot or actually i'll put an h1 tag and i'll just simply say uh we call it home page like this okay so now i'm just going to go in views and i'm going to remove this these uh variables from here because we don't need them anymore and let's run this now and see what we're getting so on the home page if i hit enter you can see now we're getting home page so what we've done is we've said okay so this is our base template the content for each of the pages that inherit this is going to go inside of this block content so if i go here and i type block content i can put whatever i want here and it's just going to paste it inside of here for me now this works the same with other kind of blocks you can create more than one block and you can choose whether you want to use them or not so for example if i want the title to be different what i can do is inside of here and there's no really limit on how you use the blocks you can use them however you want i can say block title and then here i can end this block again and you always have to end your blocks you can't just leave them open otherwise you're going to run into some issues do end block and then i can set a default title in here if i wanted to for example tim's site like that and then here i can make this block again so if i i'll just copy this actually and paste it up here and name this title and then here i can just name it whatever i want so in this case i'll just say home okay so now what's going to happen is this block title is going to be again overridden by this and it's going to put that as the title of our webpage let's try this out and you can see that now up here at the top it's changed to home as opposed to tim's site now if i go to like slash two you can see there's nothing here just because i haven't set any base stuff to show up inside of my base content if i wanted something default to show up what i would do is just type like hello or something in here and then that would show up but that's how the blocks work and that's the first step to kind of template inheritance now i'm going to show you how we can actually write code inside of our templates to do things more dynamically so this base.html file is fine this home file's fine but i actually don't want to be using this base.html file inside of my as one of my views i just want to inherit from it and then customize it from each individual view so what i'm going to do is create another view or another template my badge sorry and i'm going to call this file new file and we will call this one um is should we call it view i want to view the to-do list so maybe we'll just call it like list like that okay list.html and what this is going to do is display our to-do list for us so the name of this to-do list and then each item on the do list it's going to display that in a list form that's what i want to do so i have to start by extending from my base.html so really simple again extends in quotes i don't think it matters if it's singular double quotes and then we'll say main or base.html like that we'll set up our blocks so our first block is going to be uh the title block so my percent signs so block title and then here we'll go and block like that then inside here which our title be maybe we'll just say like view view list or something we could change that later if we want and we'll set up our content block which will be actually displaying the list for us so block content and then inside here we will obviously end the block and then inside of the content what i'm going to do now is start working with some variables that we pass in from views so actually the only thing we really need i guess is we can say ls is ls and then from there we can determine if we want the name here if we want the items we can do all that kind of stuff so let's start by just doing an h1 tag which is the name of the list so to do this i'm going to do h1 and then in here we'll put remember our two curly brace sets and we're going to say ls dot name okay because we're passing that ls object so we can call any methods on it that we want inside here so we have the name now but we also want all of the items and here's where things get a bit tricky kind of tricky but actually just really cool and how they work so we could technically have infinite items we don't know how many items we're going to have so we need to loop through all of the items and then display them in kind of a list form so to do this we're now going to start actually writing some code some python code python ish code inside of our html file so i'm going to write a for loop i'm going to show you how to do this for loop inside of your templates you're gonna start by literally just typing the four so you could say four and in this case i'm gonna say item in ls dot and then item underscore set dot all now some of you might think you need brackets here for some reason when you put the brackets you run into an issue so if you're going to be looping through something don't put the brackets like that just leave it like this and it should work so if you're running into an issue that says something like it can't decipher these brackets just get rid of them and that should work for you that's an issue that i was running into we need to also end this for loop so i'm just going to type n4 here and now inside of here i'm going to show you what we do to display a ton of different items using a loop so essentially i mean maybe just a little indent this to be a bit nicer inside this for loop i want every time this for loops runs to get the name of my item and display it on the screen so to do that i'm going to set up a list so i think what i do is i do ul i haven't done html for a while so this could be a little bit rusty do ul which stands for our list okay and then inside here what i'm going to do is i'm going to say li like this we'll end that li tag and then in here we're going to use a variable but our variable this time is going to be item dot text okay because we're gonna get the item which is that item object in our database from the item set of our list and then we'll display that as a list item now i don't even know if i have any um items in my list so we might have to add those in a second but that's fine we can deal with that when we get to it so now that we've saved this let's make sure that we're actually going to return list.html from our views so instead of returning base let's change this to list and then let's run our site here quickly okay so we get first list and we don't we're not running into any issues but i'm pretty sure the reason we're not seeing all of the different items is because we don't have any so if i want to add some let's end this and let's add some items to that list so i guess to do this now i got to refresh my memory is we're going to go python manage.pi shell and then i need to import from my database so from import main dot models alright it's from main dot models from main dot models we'll import to do list like that and then what we're gonna do is we're gonna say i guess we'll say ls equals to do list dot objects dot get id equals two we'll print ls out we see we get first list so let's look at the item set quickly so item underscore set dot all we don't have any so let's add some in there so item set dot create and in this case i guess what do we just need we need a text for that right so we'll say text equals and then in this case we'll say first item and i guess we'll do complete equals false okay so we added that let's actually add another item and we'll call this one second item and while we're at it let's do a third one okay so now we've done that we can get out of this by just typing quit and then run the server again and then see if we've updated our list let's cross the fingers there we go and now all of our list items are showing up so first item second item third item and that's how you use a for loop inside of your templates and that's really like look how cool that is we don't have to we don't have to type a ton of html we just do a for loop like we would in python we're very familiar with and then we can just type whatever we want inside of the for loop in terms of html and that will show up on the screen for us that's how that works and that's really cool now we can also do if statements and else statements and stuff like that so i will now show if statements um it's gonna be this is a hard example actually what i can do is say we'll do another blocking here and in this case what we'll do is we will only show the item if it's not if it's complete right or if it's not complete because if we're going to have it complete we probably shouldn't show it so first of all i don't know why this is trailing here and get rid of that and then here i'm now i'm just going to do my percent signs again and i'll say if and in this case item dot complete equals equals false and then i will simply end if here so do percent percent and if like that so we always have to end our statements i know it's annoying but if you think about it we're not really working with indentation in these files so it's not going to be able to tell what's in which statement unless we do an end if or we let our we end our statements so we need to do that okay so we've done that and now i will actually just go back into the shell again i know it seems pretty counterproductive and make an item that is actually complete otherwise we're not gonna see that so i guess we're gonna have to import this again so from main dot models uh import to do list we'll say ls equals to do list dot objects dot gets id equals two okay ls dot item underscore set dot create and in this case we'll say text equals not showing and then complete equals true okay so true like that hit enter not showing quit that and rerun the server probably should have done this before guys but you know that's fine so if i run this now you can see that we're not seeing that item that i just created but if i change this to be true okay and save this now and hopefully this updates quickly now you can see that we're only seeing the item that is complete so these if statements work just the way they work in python you can see only the complete items only the not complete items and yeah that's really how you do that we can also do um like an else and an elsif and stuff so if i want to do an else statement in here i can just type else and then put whatever i want underneath the else and we don't need to type end else because ending the if will tell us that we're done the entire kind of chain statement so what we'll do actually and this is kind of interesting as well is inside of here we'll do the item.text if it's complete but we'll do an all capitals complete after it just so we know that it's finished otherwise we will say incomplete like that so let's try running this now and see if i made any mistakes or not okay so there we go so we can see first item incomplete second item incomplete third item incomplete not showing complete awesome so that is essentially the basics of templates how we do the kind of inheritance for them you can obviously have a template inheriting a template that inherits another template and in future videos we're going to be making these look a lot nicer i just want to give you guys the basics here and make sure everything is working in fact let me make sure the homepage works i forget if i showed that okay it does so anyways that has been it for this video if you guys enjoyed please make sure you leave a like and subscribe if you need any help or anything feel free to leave a comment down below i'm always answering those and i love to chat with you guys so in today's video what we're going to be doing is talking a bit about forms now forms are essential to any website an example of a form of something like a login form or a create new account form or maybe a create new to-do list for our example here so we're going to be doing today is just making a form that will allow us to create a new to-do list and then in the next video we will create a more advanced form that will allow us to add items to our existing to-do list so i want to make a way essentially right now that we can create a new to-do list without having to use the command prompt i just want to create a web page that'll allow us to do that so what i'm going to do is create a new page on our website called create that will allow us when we go there to create a new page using a form so what i'm going to do is start by setting up a path to that page creating a new template and then we will work on the actual form itself so in this case i'm just going to say that create will be where we want to go and then we'll say views dot create and we'll name it create like that i think i can just probably just put create like that too but whatever that's fine okay so now that we've done that let's go into our views file let's create a new function we'll say define create we'll say response like that and then in here we're just going to return the same thing but we'll just change the file name to be create.html and we'll create that file right now so we go inside of our main file here i'm just going through this quickly because we've already essentially done this a bunch of times i'm going to extend so this extends and in this case main slash base.html and then we will have to do those blocks or we don't have to but we will do those blocks so in this case uh block title and we'll just call this create new list and then we will end the block like that and i'm just going to copy this and put it down here but just change the name of the block to be um what do you call it content like that okay so now i'll save this as what if we want to create dot html and we have created the template for our uh what do you call it create page so in here i'll just say create page and we will add the form content into here afterwards so now that we've done that we should have a page on our website uh essentially that when we go to create it'll bring us to this html page which extends obviously our base.html uh and to give you a reminder this is what our base.html file looks like okay so what we need to do now is actually create a form that will show up on our create page now when you create forms most of you are probably used to doing something like this where you go in the html and you actually code the form yourself so for example you do form you're going to say method equals maybe we're going to say post in this case and i'll talk about the different methods in a second you're going to say action equals and in this case we're going to go back to the same page and then maybe you make a button and that button is type equals submit maybe it has a name uh equals like save or something and then you end the button and maybe you do something like that so like this is an example i'm just doing this because we're actually going to need to do this but you guys get the idea that this is typically how you create a form and then above all of this you're going to do all of the different fields in your form so for example you've got a username and password you do an input field for username input field for password you give them some labels some names all that kind of fun stuff now django makes this a lot easier because all we actually have to do is pass in a variable called form and django will actually generate the html for the form that we create for us now this makes no sense right now because we haven't created a form yet but what we're going to be doing is passing a form object so we'll create our own form class and we'll create an instance of that and pass it into our html and it'll generate the html for those forum fields for us so for example if we had username and password this is all like whatever form we pass in here will automatically be generated for us you guys will see how that works in a second the only thing that we need to do when we're creating a form is make these form tags like this and then add a submit button that will um well submit the form for us that's all we have to do so now we actually need to create the form so this will start making sense now what we're going to do is make a new file inside of our main application directory and we're going to call it forms.pi so let's save this as forms.pi make sure we're in the right directory and what we're going to do uh at the top here we're going to say from django import forms and now we're going to create a class and this class is going to be called whatever we want our form to be called and it will define the attributes and the fields in our form so i'm going to call mine create new list and in here we're going to inherit from forms dot form which will allow us essentially to have the form automatically generated for us and to do a lot of cool stuff which we'll talk about later so i'm gonna set now the fields for my form now these fields are the exact same as the fields in your database so for example like boolean field integer field anything like that but what we'll so the way we do it essentially is we say forms dot in this case i want a character field for my name so i'll say character field or char field and then in here i need to give it an optional argument or i don't need to then but i can give it an optional argument of label which will be what shows up before the little box so that it um you know we know what we're typing in here and then we can give it a max underscore length as well which i believe is required and i'm just going to set this equal to 200 characters because that's probably all we need so essentially all we're doing when we create a forum is we're just going to list all the different attributes that we want for our forum as class variables underneath the the class so if i wanted another attribute that maybe was like a check button or something like that what i can do is i could say like check equals forms dot boolean fields like this and that's all i have to do and now when i pass this form into django it'll automatically create not only a name uh what do you call it a name character fields like text input it'll also create a boolean field which would be like a check button and then we could do other kinds of fields as well and if you want to know all the different types i'll leave a link here in the description to all these different kind of fields that you can use okay so that's how we create a form if you wanted to create another form same thing you would make another class and do all of the different attributes you want in that form and we'll get a bit more advanced with it actually in the next video as well so anyways now we've created a form so let's go back to this views.pi file and let's now actually pass this form into our create.html so we're obviously going to need a variable called form here and we're going to have to pass that in so what i need to do now is essentially i need to create an instance of this form and pass it to my html so to do that i have to start by importing that so oh i already imported it here but anyways just do from dot forms import and then the name of your form so my case create new list and then what we're going to do is we're going to say form equals create new lists like this now what this will do is create a blank form and we will pass that into our html and it will know what to do with it and generate the form for us on that create page so let me show you this working in action now so i'm just going to run my server i'm sure you guys know to do this by now and if i go to this link here actually when i go to slash create you can see that now we get to create new page you can see that we have a name we have a check button and we have this create new button so that button was the button that i created but this name field we didn't make this check button we didn't make django automatically generated that for us now notice that obviously these don't look great we want to add some html to them we want to add some css we want to do all kinds of stuff i'm going to show you how we can do that later but just know that django is capable of automatically generating all of the html for your forms so so before we go any further into how we're actually going to get information from this form because right now we have we're not actually doing that and it's not going to work if we actually try to submit this form i will show you how we can look at the form in a different way so for example if we go to create.html here there's a few default layouts for our form so we have as underscore table which is what is actually showing for us right now we also have dot as underscore p which will mean that the form will go like vertically down so all the items will keep going down and then we have as underscore ul which means the form is going to show up on little dots like as a list item so these are a few different ways that we can show the form um just looking like a little bit different so if i do as p for example i believe we're running the server right now and i go here and refresh you can see that now it looks a little bit nicer in terms of we have the name and we have the checkbox and they're just right after each other in new paragraphs now i just want to show you that if i try to hit this button notice that we get this little police fill out this field nice looking javascript actually pops up now the reason this does this is because django is generating the form and html for us if we had created our own form we wouldn't have we wouldn't see this this nice pop-up text right um so that's one of the advantages of using the django built-in forms although i will show you kind of the limit some of the limitations you may have with that now if i go to if i hit this um check box same thing you can see even when i'm hovering over it we get like please check this box if you want to proceed like stuff like that right now notice that if i type something in here and i hit create new it says please check this box well this box might be an optional checkbox if we want to make this not a required field then what we can simply do to do that is go into our forms and inside boolean field here we can say required equals false and now if i refresh um the website here it you see when i hovered it's not saying anything and if i type like something in here and hit sub hit create new it will work now i'll show you what happens right now when i do this and how we can fix this so when i do this it says we get a csrf verification failed now that is because whenever we're creating a form inside of our html we need to actually add these tags and i'm about to show you so essentially we need to just do crsf underscore token every time that we create a new form inside of django this just needs to go inside of our form tags don't ask me why because i honestly don't really know it's something to do with security in terms of like verification and validation and stuff so just put that in here whenever you create a form so when you try to submit it you don't run into any issues okay so now that we've done that it's time to actually start creating new to-do lists based on what the user types in so now it's time to talk about the difference between post and get requests so if i'm going to go to i'll go to views.pi for right now and we need to talk about post and get so there's two different ways to send information to the server and that's essentially what our form is doing when we hit submit submit what's going to happen is going to save all that information that was in our form it's going to bundle it up in some kind of way and send it to the server now there's two main ways of doing this post and get now the reason this like the reason they have two different ways is because there's two different functions for each of them typically technically you can do anything with get that you can do with post but they have different security reasons behind them so for post is you're going to want to use post essentially whenever you're doing something that's kind of secret so for example getting a user's password if you're sending that to the server it needs to be encrypted because otherwise if it's not then other people can very easily see the password and change it and do all kinds of stuff so you're going to use post whenever you're essentially doing anything that's kind of secret or the information needs to be encrypted when it's sended sent to the server now you also use post whenever you're making any modifications to like the database or anything like that you use get when you're just trying to simply like retrieve information so for example say i type in um like the id of the what do you call it the to-do list i want to get well we could get that using a get request not a post request because we don't like everyone can see what the id of the to-do list is that's fine we don't care about that information what actually happens when you use get is all of the information that you type in the form gets pasted in the url so when it goes to the next page it just simply reads the url and gets that information whereas post actually hides the information encrypts it and sends it to the server now i'm oversimplifying exactly how these work but i want to make sure you guys understand that you're saying post and get if you're unsure just use post but the reason you would use get over post is for example say you want to bookmark like a search result or something or you want to save some information which is a specific url then you would use get because i don't know like i'm trying to think of a good example if you ever go you ever go to any links like let's go to youtube for example and then youtube.com in this case i say like search equals tech with tim you ever see something that looks like this this is what's known as a get request where the information that the user typed in in this case it would have been in the search bar for youtube gets pasted in the url and then if you hit this i don't think this is going to work because this is obviously not the way you search for something on youtube um but it just gives you that page right whereas if i'm going to be typing in my password it's not going to save the password up in this bar because it's going to use a post request and obviously the reason we use this get request is because maybe we want to save these search results and bookmark them and we wouldn't be able to do that if we're using a post request so anyways that is how posting get works i'm sure you guys are already confused if you have any questions let me know but i'm trying to explain it as best as i can so anyways when we use this um what do you call it this create window or this create page we are going to use a post request because we want to encrypt the name of the what he called the to-do list that you are creating and because we're going to be modifying the database we need to use a post request so anyways all we have to do we don't to touch anything in here because we've already set that the method is going to be post but what happens when we have post and get requests is they are actually passed through this variable to our view so our view knows or can tell based on this variable here whether or not we are trying to post something or we're trying to get something when we access this page so to check this if we've passed a post request or a get request what we do is we say if response dot method equals equals and in this case post and this will tell us if we are trying to make changes we're passing information from the form back to this page so if we're posting we're going to be doing something different than if we are getting so those are the two requests right post or get by default it's always get but whenever you're changing something you're going to use post so anyways we're using post now so if we're using post what we need to do is the following we have to say form equals create new list but in here what we're going to do is we're going to say response dot post now what this does and what this is holding is all of the information from our what do you call it from our form so essentially when we get this response.post it's going to contain a dictionary that has all of the ids of all of our different attributes all of our different inputs and it's going to save the values that you typed in them so when you pass this to create new list what it's going to do is create a new form that has those values populated in them so by default right if we go to forms you can see that we don't have any default value for the character field or for the boolean field so what's going to happen is it's going to automatically set those values to what is received here and then we can start doing things with this form and validating it and creating a new to-do list so now that we've created this form what we'll do is we'll say um what do you call it here we're going to say if form dodge is underscore valid what we'll do in here is now we will create a new to-do list and add that with the name that was given to us so we're going to say t equals and then to-do list and we'll say name equals in this case we'll say n up here say n equals form dot clean underscore data name now i'll talk about what this is doing so essentially our form is going to take this post it's going to get all the data from the form and then we're able to access that data by just using it like a dictionary so you do cleaned underscore data you're just going to clean up the data for you unencrypt it and then what you do is you type the name of whatever the field that you want so in this case we named our name so we use name and then we can get that data and we can use it to create a new to-do list and then save that to-do list like that and that is all we need to do now so that when we use this form every time we type in a name that's valid it creates a new to-do list now this might be a little bit confusing but i hope you guys kind of understand it this is valid method is automatically created and exists because of the fact that we're inheriting from forms.form and this thing is amazing and what it does is just automatically checks all of the fields that you've defined to make sure that they have valid input if they do then this is valid will return true if they don't it will return false and obviously you were seeing that it was telling us what was wrong with uh all of the different fields when it was incorrect so let's go back to create now let's click uh i might have to rerun the server here we'll see i've saved this save all this stuff and i think that updated anyways we'll check here quickly so i go back to create you can see now we have create page we have name and we have a checkbox so let's now do like create a new to-do list called tim let's say create new and what will happen now is essentially we have created a new to-do list called tim now you might not actually be able you can't tell that we've done that but that is precisely what we've done now we can create more to-do lists i'm gonna say like uh new to-do list tim we could say like joe create that uh and that has created a new to-do list for us so now let's actually show that to-do list right after we create it so for right now all we're doing is just returning the form with whatever information we passed in it but what we can do is we can say that all right if we're saying response is post instead of returning that form that has the name of the to-do list we just created let's redirect to that to-do list so you can see what it looks like so to do that what we can say is we can say return http and instead of saying response this time we'll say http and then response redirect if i can get my capitals working here redirect like that and then in here all we have to do is put the page we want to go to so in this case i'm going to say slash and then i like a percent i i'm going to say percent and in this case i'm going to say t dot id which will be the id of the to-do list we want to go to now i also just have to import this http response um so i'll do it up here so from django.http import http response redirect and now what will happen is instead of returning this form and returning the main dot create html page we will redirect to the page that we've defined here which will be the id of the to-do list we just created so now this should have updated it did so let's try this again with joe and say create new and we are redirected to the page that displays joe to us right uh and that is essentially how that works so that is the way that you create a form if we wanted to um let's say get more information from the form what we could do is print out um like if the checkbox was hit or not we can do all kinds of stuff you can obviously create more than one form by doing multiple forms in here you can have more than one form on each page with different submit buttons all that kind of stuff in the next video i'll talk about creating custom forms so modifying some stuff maybe making some things look better and then in future videos we're going to be adding bootstrap to our website and we're doing login forms all this kind of stuff so if you guys don't get it now we will be going over more of it in the future but these are just kind of the basics of django forms so today's video we're going to be going a bit more advanced with forms i'll be showing you how to create your own custom forms that are a bit more dynamic than typical django forms that we were using in the last video using that forms class and whatnot so yeah i guess let's get into it so the goal today kind of is to allow the user to add an item from their to-do list so right now we don't actually have any way for them to add items we only have ways for them to add new to-do lists so we're going to do that we're also going to add some check buttons beside the to-do list items so we can show whether or not they are complete or incomplete without having to do this incomplete complete kind of thing so right off the bat i'm actually just going to delete this incomplete and complete for now and i'm going to start setting up a form inside of my html file here now the reason we need a form is because we need to pass the information like whether the user clicked a check button or whether they what item for example they typed in to add to the list we need to pass that back to our view using a post request so we need a form to do that so i'm going to start by creating a form i'm going to say method equals and in this case post and i'm going to say action uh what do you call it equals pound like this okay or number sign whatever you want to call it now i will simply close my form by doing that and now i'm going to start by just setting up some buttons at the bottom of my form that says save and let's say add item so what i'm going to have is i'm going to have two buttons save add item save is going to save you the changes to your checks and add item is going to add the item that we will get from a text field that i'm also going to add so the first button that i'll create will be that save button so to do that i'm just going to say button i will say type equals and in this case what do we need type for a button yeah we do we'll say type equals submit we'll say name equals and in this case it'll just be save and i'll say value equals and i can say save here as well now when i close my button i'll put whatever i want to display on it here so in this case i'm going to say save and i'll copy this actually and i'm going to just use the same thing except instead of name i'm going to say new item i don't know why that tabbed there and we'll give that value of new item as well and obviously now i'm just going to make this add item i mean i could make a new item too it doesn't really matter and in between here i'm going to add an input field which is my text that you're going to type in for when you create a new button so i'm going to say input we'll say type equals text and we'll say name equals i guess we could say item why not uh i know it's probably not the best name actually let's just say new all right news probably not a good name either but whatever that's fine okay so type equals text name equals new and sweet now what i'm going to do now is add those check buttons in beside all of our items so obviously if our item is complete we want that check button to start off as checked and if it's not we want it to not be checked so to do this it's similar to the text we're just going to say input we're going to say type equals and in this case check box we'll say value equals clicked and you can call this whatever you want but just remember this name because we're going to need to use this i'm going to say name is equal to and this is a little bit weird but we're going to set the name equal to the id of our item so to do this what i'm going to do is just go in here and say item dot id and before that i'm going to put a c so that what we're going to do now is we're going to say all of our check buttons because this is going to create a bunch of different check buttons right they're going to be given the name c and then whatever the id of that button is this will just make it way easier for us to determine which check button was checked and what item that corresponds to and you'll see how we do that later so let's copy this now and i'm going to put it right here as well so inside these li tags now the only difference is up here where it says is complete if item.complete equals true i'm just going to type checked like this which will default it to start off checked that's all that's going to do for us okay so now we've actually set up this form the last thing to add is our csrf token that we always need to add whenever we create a token or a form sorry so csrf underscore token like that and then hit save so now that we've done that our html will be showing up all nice and now we just need to handle this from our view so remember our view is called index so what i want to do in here now very similar to create is i want to first off start by checking whether or not we have posted something or we're getting something so if we're posting something we're going to say if and then this case response dot post or not post sorry dot method equals equals post like that then we will start doing all the stuff in terms of saving and adding items now i want to quickly go back here and talk about something for a second so right now we have two buttons we have save and we have new item and these buttons might have different functions and they do in this instance so for example save well we only want save to look at and update the check buttons right that's what it's going to do it's just going to update your check buttons if you've completed an item or if you haven't completed it whereas our new item button or add item button is going to take the text from this text field and add it as a new item on our list so we need a way to determine which button we clicked so we can determine what function we're going to perform so to do this what you can do actually is you can say if response dot post dot get and then here you can put the name of your button so in this case i'm going to say we'll start off by doing save save like this okay now what this does actually is whenever you get a post request from the server what's going to happen is all the information in this form here is going to be passed in what's known as a dictionary to our view so what's going to happen is we're going to get a dictionary that looks something like this so we'll have save and it will either have no value or it will have a value of whatever we typed here's value so for example save if we click this button what's going to happen is it's going to be added to a dictionary which is all of the information from this form and it's going to be given this value only if we click it so what's going to happen is we're going to get the name save points to the value save and it's going to look like this precisely okay we're also going to get all of the information for our check buttons so what will happen is we'll get something like c1 which will be that id right c1 and that'll point to in here it'll say and i'll print this out after you guys can have a look at it it'll say clicked if we clicked the check button if we didn't click the check button we're just going to get a blank string or c1 might not even show up in the uh the dictionary okay so and then we can also try what do you call it for example like add item we can do the same thing with add item now the thing is if we clicked add item then it will come in and it will give the value of add item otherwise it won't give us any value just give us a blank string and you guys will see how this works in a second i'm going to print it out for you so you can have a look so let's actually if we are posting let's print response dot post like that so you guys can have a look okay so anyways so we're going to see if we are saving so if we're saving then this will evaluate to true because there'll be some value so that'll just work otherwise we'll say what do you call it l if response dot post and dot get and in this case instead of saying save we're going to say new i think was it new item i keep forgetting what i call this yes new item awesome new item okay so we'll just pass down here for now and let's work inside of this first one up here so what we want to do up here is we want to look at all the different check buttons and determine whether or not they were clicked or not and then update our item accordingly so to do this what i'm going to do is i'm going to loop through all of the items in our current to-do list because we still have this value up here and we're going to check the ids of that with the check buttons and see if it was clicked or not so to do this i'm going to say 4 i guess we'll say item in in this case ls dot item underscore set dot all with lowercase l's okay then what we will do is we'll say if and in this case response dot post dot get and here what we're going to do is we're going to say c plus str and then item.id now what this is doing is getting the item id converting it to a string and adding a c to the beginning of it so we will get the exact same kind of pattern of what do you call it names or ids as we're setting up here right so we have c in that item id that's just what we're doing here so if we get that and that is equal to the value of clicked then what we need to do is well we need to update that item so we'll say dot complete is equal to and in this case true now otherwise so if we didn't get that or it wasn't equal to clicked we'll take this but we're going to set it equal to false so this is the same as like if you unclick the check button and it doesn't um it's not check mark then this will run right here what i'm doing now and then all we can simply do down here is just say is actually inside the for loop we'll say item.save and there we are sweet so that's how that works and that's actually it for this uh saving the check buttons now what's left to do is to add a new item this is uh it's similar in terms of how we do this but what we're going to start by doing is getting the text that was in that text input field here so the name was new so say text is equal to and in this case response dot post dot get and here we'll say new and now what i'm going to do is before i add this new item because this will give us the text i want to validate that this is valid input now you can do whatever checks you want on this input and usually django will do it for you but since we're not using django forms using our own custom form we don't have that option of using is valid like we used here so what i'm going to do is just say if text and this will actually say len of text is greater than two so it's at least three characters then i will simply add that item to the to-do list so to do that i'm going to say ls.item underscore set dot create and in this case we'll say text equals and i'm actually going to have to rename this to txt here i will say txt and then we'll say complete equals false like so uh otherwise i'm just going to print out a message that just says like invalid input just so that we can have a look at this in the console and that should actually be about it now i'd be surprised if i didn't make any mistakes but let's give this a run i already have the server actually i'm gonna have to run the server again here run the server so let's now attempt to go to like id2 so now we can see we have first item second item third item not showing now if i decide to check an item or uncheck an item and hit save uh um what is your issue here name respawn oh well it would help if i spelled response correctly where did i misspell that re of course in the print statement anyways let's see if this will update now python managed up high run server did i make another mistake let's see two okay now let's try it save there we go so then you can see that the item saves now if i go to maybe let's say page three and i want to add an item let's try hello and we click add item and now you can see that we get hello popping up and i can check i can save that i can unsave it and if i go back to 2 you can see that obviously the same checking pattern is still there i could add a new item so i'll just say new item here add that and you can see that it's popping up and i can save that so that is how you make a custom form this is very useful what i've just shown you will allow you to do pretty well anything with forms because now you know how to get information from forms now i will show you actually what our post requests are looking like just so you can see or sorry uh what is it requests like what i'm printing here i'll show you what that looks like and talk a little bit about that before we wrap up here so you can see that uh if i go here we have check button c2 and that is given a value of clicked we can see c5 is given a value clicked and c7 is given a value clicked so those ids for our check buttons we see that save is given the value of save because we hit that save button but we see that we're not seeing any other um values here right so if we don't click an item or if we're not giving a value to it we're not going to see it here so for example like if we have c2 and we don't check that button it's just simply not going to show up in the information that it passed to us which means that we can check if it's not there and then do something accordingly so the way that this get request works when we say get like this or this get method is since this is it's like this is kind of a dictionary but this get method is specific to this type of data structure and essentially if the item doesn't exist i believe it just returns none which means that if we ever put something like this so for example if save isn't there we simply won't run the block because if none obviously it's not going to run so that's the way that that kind of works you can see i mean i wrote highly encourage you guys to kind of mess with this and do some requests print them out and see what it looks like that's really the best way to understand how this works um you can see it's a type query dictionary and when you try to get something if it doesn't exist it just says none if it does exist it'll give you the value that corresponds with it and in some instances you can actually have multiple values pointing to the same name so that's just something to keep in mind that you guys might notice when you go through this so anyways that is essentially how that works we create a custom form now we know to add things and with this information we can go into creating some more complex stuff so in the next video i think i'm going to be adding bootstrap onto the website making things look a little bit nicer maybe adding a sidebar we'll do some stuff like that and then later on we're gonna get into user registration and all that kind of stuff so that you can actually have all of your to-do lists stored under a certain user so anyways that has been it for this video if you guys enjoyed please make sure you leave a like and subscribe and i will see you in another video so in today's video it's going to be a little bit shorter and what we're going to be doing is simply adding a sidebar to our website and making things look just a little bit nicer now in the next video we're going to go on to add bootstrap to our website and then be able to make something that looks pretty well like this and i'll show you guys some more of this example in a second but for right now we're just going to be adding this nice sidebar with some hovers and kind of showing you how to go about doing that so anyways let me give you a quick preview on what our website is going to look like in the next two maybe three tutorials so for example we have these links on the side here we can view all of our different to-do lists so if i go to new lists you can see that we go there we can go to create which will allow us to create a new to-do list and then obviously if we go inside of a to-do list we can see all these nice check buttons we can hit save we can add a new item for example by doing that and this is just kind of the basics i haven't gone crazy with this i could obviously make this look a lot better be a lot more dynamic but this only took me about 15 15-20 minutes just to style and make everything look decent so anyways that is kind of what we're going to be working towards in terms of using bootstrap which is just some css that's pretty much already made for us and adding a sidebar today okay so let's get out of this and let's go into our what do you call it file here and all we're going to be doing to add this sidebar is working inside of this base.html file now because all of these files inherit from base.html this makes it really easy to add stuff like a sidebar to our website because all we have to do is add it into the base template it will automatically be added to all of the other ones now what i'm going to start by doing is just setting up a div here that's going to represent our sidebar and if you're not familiar with html and css and all this stuff i'll try to explain how some of this stuff works but it is pretty straightforward you should get it pretty quickly so i'm just going to say the class is equal to and in this case side nav like that and then we will end that div and inside here i'm just going to put a few links which will be our sidebar items so in this case i'm going to say slash home and this link name will be home like that and copy these a few times okay so home will have create and then we can add one more link if we want to uh but we don't actually have anywhere for this to really go to yet let's just do like slash two and just call this uh view okay so anyways what i'm doing right now guys uh in case some of you are confused essentially is this href just stands for where this link is gonna go when we click on it a stands for link tag and this div is just a way that we can style a bunch of different elements at once by doing for example class equals side nav and now what we're going to do is up here in our head tags is we're going to create a css kind of script or style sheet within our html file here and define what our side nav is going to look like now we also need to add a class here to our main div because i'm going to add some stuff in here and this class will just be called what was it me like that okay so anyways what i'm going to do now is go up top here and i'm just going to add a bit of styling stuff to make this div here that we've added of links appear on the side of the screen a certain color and then add some hover effects and stuff to it as well so this is really just going to be adding some css at this point so i'm just going to add some style tags here i will close that style there and in here i'm going to do type equals and in this case text css like that and now i'm actually just going to copy off my other monitor because i can't remember all of the styling i've done on this but essentially if we want to access or change the side nav class what we do is we use a period representing a class and then we type the name of our class which is sidenav we can add these brackets like this and then inside here is all of the styling we want to apply to our side nav so for example we want the height to be equal to 100 pixels which are sorry not 100 pixels 100 percent which means that it's going to take up the entire height of the screen so you saw that on my left side it took up the entire height we're going to say width and in this case we'll just give it a pixel value so 160 pixels and you can modify this value if you want we're going to say position and in this case it's going to be fixed we could make this a dynamic sidebar but i'm not going to do that in this part we're going to say z index and in this case 1 which means that it's going to stay all the way at the top of our screen we're going to add top which is zero we're going to say left zero like that which just means again stay in the top left hand corner of our screen we're gonna say background and in this case is it even there uh it's not background i believe color and we're gonna say this is pound one one one which will give us that kind of dark blackish gray color you guys saw before we'll say overflow x and this is hidden and i don't even remember what this one does oh it just makes sure that we don't go horizontal uh with our sidebar and then we'll do padding from the top uh of 20 pixels now just to as a disclaimer here i did not create the sidebar i just found this on some like css website and modified some of the attributes so that's what i'm going off of here if you guys want to create a different kind of sidebar you can feel free to modify these kind of properties change the color like they're pretty straightforward on how they work or you can just look up like nice sidebar a nice title bar online and we'll probably give you the css and even the html on how to do that so now i'm going to set up what my links inside of my sidebar are going to look like so whenever you want to specify a certain tag from within a class you do the class name and then the actual tag itself so in this case side nav a which means if i highlight this you can see it's actually highlighting all of these a tags here that are inside of my sidenav so what i'm going to do here is say padding and in this case we're going to say 6 pixels no 8 pixels 6 pixels and 16 pixels and again feel free to mess with these numbers we're going to say text and in this case decoration and this will just be none for now and then down here we're going to say font and you guys can mess with this as well you have to look up the fonts if you want to know what these mean is eight one eight one eight one and display in this case is gonna be block style so is that all uh oh sorry what am i saying this is color and the font i must have misread this here the font is going to be just we're going to do the font size which is 25 pixels like that okay so that's it for the sidenav a tag and now all that's left to add is actually what happens when we hover over our aid tags so for example if we hover on these we want to change the color so we can do that from within css so to do that what we're going to do is literally just copy this except we'll add this what we call a property here called hover and then all we're going to do is just simply change the color when we hover so to do this we'll just change this color to f1 f1 f1 and yeah there we go okay so we've done that now and the only thing left to do actually is move this uh what do you call it this main content here over to the right because right now what we are actually gonna have is we're gonna have the sidebar and then this content will go below the sidebar we don't want that so to move this content block or i guess this class main over it's pretty straightforward we'll do dot main like that and then in here we'll just say margin hyphen left and in this case is 160 pixels did i spell margin correctly no i did not and we'll just add a bit of padding here so say padding and then in this case we'll do 0 pixels and 10 pixels like that now that should be about it actually for our sidebar and by applying this to our base.html file this will apply to our entire website so let me actually get back into my uh what do you call it file here so i can run this for you guys so cd django tutorial cd my site and in this case we'll just do python manage.pi run server and let's grab this link here go to google chrome and let's see how this looks okay so there we go so we've created a nice home page here you can see we have home create view if i go to home uh so slash home doesn't exist that's just my bad i don't have a slash home page here and if i go to create you can see we have this nice little create now and if i go to view it brings me to uh list item number two or whatever it is or to-do list number two so that is precisely how we add a sidebar and you can see that this is a really nice thing that we have essentially is the fact that we have this base.html file because look i just applied the sidebar to my entire website really easily so now i actually i feel like i must have forgotten some kind of font size here because on my other website the font looks better but um you know what for now that's just fine so anyways uh that is actually going to be it for this tutorial i know this was a bit shorter but this shows you how to add a sidebar it also kind of shows you how you can style some of your different items if you want to add some more content blocks or you want to add classes to specific things you can do exactly what i've just done here inside of your other files as well you can add some style tags or you can add the style tags here and then add the classes on stuff like this and yeah so in the next video we're gonna be adding bootstrap to our website which is a nice css styling and we'll make it look a little bit nicer change some of the fonts and just make everything look a bit cleaner so anyways that has been it for this video if you guys enjoyed please make sure you leave a like and subscribe and i will see you again in the next so in today's video what we're going to be doing is just adding bootstrap to our website and doing a little bit of styling i'm going to show you guys how we can add some just nice looking classes and how you can kind of look through the bootstrap documentation to find what you're looking for so all we'll do is really just style a few different elements and make things look a bit nicer and then i'm kind of going to leave the rest to you guys so with that being said let's get started so i'm going to head over to the bootstrap website and it actually gives you a really easy and quick way to get bootstrap on your website and all we're going to do to do this is just kind of follow this page so first let's talk a little bit about what bootstrap is so bootstrap essentially is a css javascript jquery framework which allows for you to add some custom built styling to your website now this actual framework is built on what's known as a mobile first site framework or like so it's meant for building responsive mobile websites that and then they will expand to desktop applications so apparently that is kind of the best way to do it now is to build stuff ideally for mobile because that is where most of the web traffic is nowadays i believe i could be incorrect um so you build it first for mobile and then you kind of expand it out into desktop so anyways let's get started and use bootstrap so what we're going to do is just follow this page so the first thing we need to do is copy this link here so css and i'll leave the link to this page in the description if you want to do this as well so i'm going to copy this style sheet here and all this uh all this is essentially is this kind of style sheet but just online that we're going to access and be able to use so it's served on what's known as a content delivery network which means we don't actually have to download the style sheet we can just copy this link in here at the bottom of our head tags but just above the title and we will start using this uh this style sheet on our website now that we've done that there's a few other things we need to add so let me go down here to the starter template and just copy a few things we're missing the first thing i'm going to add is just these meta tags and these meta tags apparently are important they just set up some properties for your website so we'll put them below this link like that just to finding the type of characters you're going to be using and then i believe this is something to do with the mobile friendly kind of look or whatnot so now that we've added that they might have to go above that we'll add those above we'll add this doctype html so just exclamation point doctype html we'll add that at the top of our file like that hit save and i'm just going to move these meta tags to go above our link here so our style sheet like that sweet so now that we've added that there's only one more thing is three more things actually that we need to add and those would be these scripts and these scripts are used by some of the css classes and to do a little bit of animation and just make things look a bit nicer maybe move some components around the page so we're going to add these at the bottom of our body tag so underneath all of the content here now you don't necessarily need to add these scripts but in some cases when you use certain css classes they will require these and then things might look a little bit funkier things might be off so anyways now that we've added that we're actually ready to start using bootstrap so the first thing i'm going to do is kind of add some divs and some different classes into my main content block here and i'll talk briefly about what they do but really the way to understand this stuff is just to go to the bootstrap documentation so for example if i go here and just look at all the different components and kind of copy the stuff that you like that what it looks like and then customize it so for example if you wanted a large button you would go to the buttons tab here for components this link will be in the description as well look at a button you like and then literally just copy the tag or the class for it and then you can customize it accordingly so that's what i'm going to be doing for this kind of and i'm just going to be copying some code that i've already written to style my website in a way that i think looks i mean decent okay i haven't gone too far i didn't take too long to do this so anyways let's add some dibs here so the first div i'm going to add is class equals in this case row and then justify in this case content content and center like that which just is going to mean that we're going to put this in the middle of our web page so yeah so add that and now what we'll do is we'll add another div and this div we're going to say class equals and in this case column 8 which is going to define what column space we're going to be in we will end this div here and we'll add a few other things as well so now i'm going to add an h1 tag and this h1 tag is actually going to be the header of my website so inside of this tag you're going to call whatever your header you want so i'm just going to say mine is my site and i'm going to give this a class of in this case we will say mt hyphen 2. again i'm just taking these from the bootstrap website if you don't know what this stuff means you can either just look up the class and it'll show you the styling for it or you can just go to the bootstrap website and look for ones that you like so in this case i'm going to do mt0 mv hyphen 4 and what this is going to do is draw a little line for us underneath our header just make things look a little bit nicer so that's all i'm actually going to add here for this main base template now let's go to our website and let's see how it looks so this is what it looked like before and just with those few adjustments when i refresh the page let's see how it looks now okay so there we go um so actually so these little check buttons here shouldn't be here one second guys just because i might not have saved a page because i was messing around with it before let me refresh this now ah there we go so that's uh now what we're getting now it should be in the middle of the page which is kind of throwing me off just a little bit uh i spelt justify incorrectly that would be why so row justify content center i knew i was doing something wrong there so now let's refresh this and there we go now we can see that it's moved to the middle of the page and we have this line here obviously as well still sweet so that's it for just styling the base template so now that's going to apply to all the web pages that we have if i go to create for example you can see that it applies to this as well so now it is time to style some of the other pages that we have so the first one i'm going to style is this create page so notice this is what it looks like now let's mess around with this now what i'm going to do is change some aspects of this form so i'm going to add a class here and i'm going to say this class is form hyphen group i'm just going to put this create page into let's say like an h3 tag for right now just because i want it to be a little bit bigger on the page it won't add any uh any styling to that so now we'll add some divs inside of this so the first div that i'm gonna have is just gonna be an input group so i'm gonna say div and in this case class equals input hyphen group in this case mv hyphen 3 and then i will end this uh like this i believe this might be the correct place for it i'm probably gonna have to mess around with these a little bit but we'll see i'm also just gonna put this form instead of doing form dot as p i'm just gonna get the name attribute from our form so the way i do that is just by saying form dot name so rather than showing the entire form because we have a little check button i'm just going to show the name text box because that's all i actually want for right now so now what i'm going to do is actually i'm going to move this underneath here my apologies and i'm going to add another div and this one is going to be class equals and in this case input hyphen group hyphen prepend now this is a really nice um div that they have here the class that they've made and what this does is well you guys will see in a second is it makes this button kind of mesh with this text input so they go they look at like in one line where it has the button and then it has the text input field right beside it but they're like combined together and it looks really nice you guys will see in a second how that looks now the last thing i'm going to do is just add a class to my actual button itself so i'm going to say class equals in this case btn and then btn hyphen uh what was it success i believe yes btn hyphen success and that might actually be it for all of my styling for this page so let's go ahead and have a look now and see how this looks if i run this there we go we get create page and now you can see what this pre-pen did it took this button and it put it on the left side of my text input and notice that we get this little these little things coming up this happens obviously because of uh some of the javascript and stuff we have please fill out this field you can see that's there if we go to create new uh we can see that pops up with there's a hover for it it's just all this nice stuff that bootstrap does for us some of it's done by django but most of it's done by bootstrap now let me go to view so now it's time to make this one look a little bit nicer so let's go ahead and do that and then we'll wrap up the video here so this will be a little bit more tedious but let's actually get rid of this kind of ul view and tags and stuff because i don't think we're going to need to use these yeah so let's get rid of these uls and let's get rid of these lis because right last time we're just using lis to make them show up in a nice kind of group but we'll use some uh some classes here from bootstrap to do that for us so we can uh tab this back so let me do that actually i probably should just left it cause i'm gonna have to put this inside a div but anyways inside of our for loop now i'm gonna create a div i'm gonna say this class is equal to and in this case input hyphen group and then we'll do mb hyphen three and then i'm going to add a prepend in here as well because i want to combine these check boxes with um what you call it the text which we'll add in a cool way in a second so i'm going to delete these text right now and what i'm going to do is add a prepend here so i'm going to say div and in this case class equals and in this case what was it it was something like prepend input group hyphen prepend input group hyphen prepend let's tab these in we will end this div and we will end the other div as well just make sure we don't forget like that so now what i'm going to do is outside of this this div but inside of the other one i'm going to add that text that i have back in so i need to actually get the item text i'm going to add this though in a weird way i'm going to add this in an input box so the way i'm going to do this i'm going to say input and in this case we'll say type equals text and then we'll simply just say value equals and in this case we'll say was it item dot text like that now we'll add a class to this as well we'll say class here equals and in this case form hyphen control and there we go now that's it for the kind of displaying the items let's actually have a sneak peek of how this looks and see if i made any mistakes or not um okay so it's not ideally what we wanted to look like but you can see we have these text box and we have the check buttons let me make sure i didn't make any critical errors here before i might have either misspelled something or forgot to add something ah so i've forgotten one class which was probably pretty important here so we're going to add another div and in this case we'll say div class and in this case equals input hyphen group hyphen text we'll end that div where is this div ending i believe right here and that should be good for that i don't want to say for sure but let's see there we go so that's better this is what i wanted now you can see we have the check buttons kind of showing up on a nice little color here and then all of our items show up in text boxes and i mean you can actually edit the items but when you save them it's not gonna it'll just go back to whatever you had but i just wanted to do them in this way because it looks really nice and now what's left to do is just modify these buttons here so let's go ahead and do that so what i'll start by doing is adding a class or a div here so i say div class equals in this case we'll say input hyphen group in this case mb hyphen three i will tab all of these i guess except for let's see which ones i actually want i'm going to put the save button i think on a different side so let me put this save button down here and i'll tab these two in these add items and i'm actually going to do the same thing that i did with the creating a new to-do list in terms of that pre-pen thing with these items so to do that i'm going to add another div in here and in this case i'll say div and then class equals in this case input group hyphen prepend you guys can tell i like this this pre-pend thing that you can do here uh prepend we will tab these in and then we will close these div so slash div and slash div but i believe that i have to put this input actually right here and that i think is correct there we go sweet so now all i need to do is add some classes to the button so i'll add the same classes that i used on the other one so i'll just say class equals in this case btn btn hyphen success and i'll just copy this and we'll use this class down here as well just to be consistent so anyways that should be it for styling let's have a look now if i refresh uh continue there we go so now we get add item and we get save and things are just looking a lot nicer on our website obviously there's a lot of work to be done but take in i did this in 13 minutes in a video or however long this video is and i've been kind of explaining things as i go but i'll quickly show you that if you want to look at the different components and see all this different kind of stuff just go to the bootstrap documentation this is the link i'll put in the description go to components here and for example if you want to look at a nav bar and how this works that it'll explain to you how to create one and you can just really copy kind of however whatever you want from here if i go to for example buttons you can see all the different kind of buttons and how to make them and it just tells you what classes to use you use those glasses and then it looks nice on your web page so anyways that has been it for this tutorial if you guys enjoyed please make sure you leave a like and subscribe and i will see you again in the next one so in today's video what we're going to be doing is talking about user registration and how to create an account on django now fortunately for us django actually does quite a bit of the hard work at least for us so all we have to do really is format a form and then just add a few things to our project it is a bit of a tedious process but it's much easier because of django and another reason why a lot of people love django because it does stuff like this for you you can see right now i have open uh the thing we're gonna be creating now this is just in a copy of the project that i'm working on and i just made this to make sure it was gonna work uh create account page and we're gonna be making this to start we'll be adding an email field to this as well or like an ad name or something like that field to this as well and yeah that's kind of all we're gonna be doing today in the next video we'll talk about how to log in and how to log out and then how to restrict access to certain parts of the website to certain users so for example the admin user can access the admin dashboard and they can see all of the different databases and all that whereas a regular user won't be able to do that so let's get started now the first step and what we're going to have to do to do this actually is create a new application so what i want to do is right now we already have an application called main but i want to create an application now called like users or called register or something like that that is going to handle the login logout and registration for our website now this is the reason i'm doing this is also so that you can just copy this application and put it into any other django project and because it just kind of makes sense to separate things out so to do that we're going to go to our command line and we're going to create a new app using that python manage.pi file so we're going to say python manage.pi and we're going to say start app and in this case i'll just call mine register like this you can name yours whatever you want but i'm just going to say register so there we go it has successfully executed and now if we go to our directory we can see that we have register popping up here now what i'm going to do to start is i'm just going to uh what do you call it modify some urls so we're going to add a page that we'll be able to use to register because we need a register page so let's open up subline text here um let me just open up a new window why is this not working uh one second guys file uh open folder here we are okay so django right there okay so there we go now we're in django and what i'm going to do is i'm going to modify the urls from within my main file here so that we're going to link to a view that we're going to create inside of our new application called register so if i go to urls here you can see that right now these are our main urls that we have inside of our main application but what i want to do is go to the urls inside of my site so let's do that here and what i want to do is just add a new path that's going to direct to a new page and in this case i'm just going to call this one slash uh create i guess or actually not create let's do uh register so like registering for a new account we'll call it that and what i'm going to do is i'm going to link this directly to the function that's going to render this from our register application so what i'm going to do inside of register now and i'll come back to this in a second is inside of views.pi i'm simply going to create a function in this case i'm just going to say define we'll call it register as well it'll take response and then in here all we'll do is just return render and then we will render something in here in a second but we'll just fill that in for right now so we go back to urls what i'm going to do now is i'm going to import this file in this function so that we can use it from in here to link directly to that view so to do that i'm going to say from and in this case we'll do register because that's the name of our folder uh register import in this case views as and i'm just gonna say v now the reason i'm saying views as v is because we could possibly be importing some more views into here and all of them are going to be called views right like the views for this application is the same as the name of the views for the main application so just by doing it as something that way we're going to differentiate them so we don't run into any mistakes essentially so now i'm going to say what we'll go to is we'll go to v dot in this case um actually from register import views we'll go to v dot register like that and we'll say name equals in this case register now add that comma and we should be good in terms of linking to that okay so now that we've done that what i want to do first of all is create an actual page that will be our register page which involves creating a template for that so i need to do the same process i did to create templates within my main application and that is starting off by creating a new folder inside of our register application and in this case i'm just going to call it templates uh templates like that and then inside of templates i'm going to create another new folder and if we remember we call this register now inside of register i can create my file which will be my register.html file which will display the form that we're going to see so i'm just going to start by extending my base template and the way that we do this now because this is in what he called a different directory is the exact same as before we just have to specify where we're getting it from so we're going to say main slash based.html and then what we're going to do in here is we'll do our blocks so we'll have the block title and we'll have the block content so block title and in this case we'll just say create an account or something like that and then we can end that block and block and then now we'll do our block content and then we will keep going from there so say block content and then here we'll say percent percent and block now we'll save this as register.html inside that template file and there we go we have now created the file that we can render and display on the screen now while we're in here i'm just going to fill this in and populate it and all i'm going to do essentially to do this is i'll use a little bit of style a little bit of bootstrap styling and then just display the form inside of here using the way that we can just display django forms and then you guys will see how it works in a second anyways so let's start by creating some form tags we'll say form in this case we're gonna say method equals post because this is going to be the form to create a new account so obviously it's going to have to be post method because we need to make sure that information is secure when we're sending it to the back end say 4 method equals post i'm going to say class is equal to in this case form hyphen group and then we'll end that form tag and in here we will simply do um what do you call its form like this now the only other thing we need to add is a button and this button will be the submit button because by default django doesn't generate that for us so what we can do to do this is just say button we can say type equals if i didn't hit insert there we do type equals submit submit like that and what else do we even need for this we say class equals in this case btn and then btn hyphen success i believe that's the class name and then we can end that button tag and inside here we'll just say um what do you call it join or like register like that and that's what we're gonna do for now we'll make this look a little bit better after but that's all we really need for right now okay so now that we've done that we've said well we're gonna pass a form to this view so that means from inside here we're gonna have to be passing a form now what's really nice is django actually automates the form uh for what you call it logging in and creating a new account it makes one for you that you can just use so what i'm gonna do is simply import the built-in django form and then we're just going to use it inside of here to pass to our register template so the way that we do this is we have to i'm actually just going to copy these in because they're a bit long and i don't want to mess up the uh the spelling we're gonna say from django.contrib dot auth import login import authenticate and then we're also gonna import uh from django.contrib.auth.forms we're gonna import user creation form now this user creation form is what we're going to use to create a new user and this a pre-built form just like when we went into our application and we created our own form using the django built-in forms this one just already made for us and we can go ahead and start using it right away so to use this i'm going to say form equals and in this case user creation form and then when i render my template i'll pass response we'll do in this case register and in this case slash register.html and for the context here we'll pass in form colon form so assuming i spelled everything correctly now if we actually run our server and go to this we should see a form showing up uh actually one step for that that i should not have forgotten but i almost did we need to add our application in this case which is register into our settings.pi file because if you remember when we initially created a new application you can see that we added this main.apps.mainconfig well we need to repeat this process now with our new application which is register so let's just copy this and paste it down here and instead of having main we're going to change this to just be register and here register as well remember that capital at the beginning okay so now that we've done that assuming i didn't make any mistakes if we run the server we should be all good at we should be able to see all this stuff so let's do this now we'll say python manage dot pi and in this case run server okay no issues so let's grab that let's go actually i'm just going to refresh this and it should pop up and now you can see that we are actually getting this beautiful register window now i'm saying that sarcastically because obviously this does not look amazing and we're going to work on styling this and making it look a little bit better in a second but you can see that we actually have a somewhat functional user registration window already created for us and you can see it says required 150 characters uh this is the thing that you need for passwords and then it asks you for username password and all this stuff and then there is a register button that we created so that's awesome and that works well now all we the thing is though if we actually type anything in here so for example i say tim and make my password one two it says oh your password cannot be entirely new numeric it must be at least eight characters okay let's just type let's save a bunch of letters for example and if i type a bunch of other letters and hit register we run into an error that crsf csrf token is missing so i'll have to add that but my point here was going to be that this register button doesn't actually do anything just like when we created a form before we actually need to add the functionality to save the form and create the new user which is what we will do now after we add that token that we need so let's add that token first of all inside of here cs csrf underscore token and now let's go into view stop pi and let's check how we can validate this form and how we can actually save things using it first of all before we start styling it too much so we're going to do is what we've done before so we're going to say if response dot method equals equals and in this case post then that means that we are going to be creating a new user so what we'll do in here is we'll start by saying actually we'll take this form we'll put it up here and inside of here we'll populate this with response dot post now it will say say if form dot is and i believe it's underscore valid what we can do to save the form which is very easy is literally just say form dot save and what this is going to do is actually save our new user in the users database for us and i'll show you how this works in just a second but let's add this else here so that we create a blank form if uh for some reason we're not getting that post request right so this is all we need to do actually to handle and make this form work obviously we're going to be doing a lot more here before we're finished but this will actually allow us to have a valid form so let us try to get this working now so let me go back here and let me refresh the page and now let's try to create an account and let's say let's make an account tech with tim uh we can just make the password check with tim123 okay and let's hit register all right um what was the issue the password the two password fields did not match okay so you can see actually as well maybe that was good that i messed this up uh it even gives you messages when things are wrong with the form so it says the two password fields didn't match so that obviously means i spelled something wrong so let's try that again and hit register the password is too similar to the username oh man see this is this is why we use django forms because they do all this wonderful stuff for us okay let's try this now tim with tech how about that uh tim with tech123 tim with tech123 register the password is too similar to the username okay i'm just going to use one of my own passwords and hopefully it doesn't show it anywhere on the screen okay so now we've registered and i actually create an account um called tech with tim and i've i've done that i know it doesn't look like anything happened but that's what we're gonna add as well next when we create an account we'll redirect to a new page but let's try going to the admin dashboard here quickly and see if we can see this new user in our database so let me sign in here and if i go to users you can see that now we actually have two users we have tim which is the admin user which is me and we have tech with tim which is the new user that was just created so if i go into tech with tim that's like the password hashing and stuff and then you can see that it has the name and that's all that we have for right now so the next things that i want to add to this now is how we can get like an email or how we can get a first name and a last name for example and how to redirect to a new page once we've created an account so once we've created an account what i'd like to do is redirect to a new page so to do that what i'm going to do is from django.shortcuts import render import redirect and all we'll do in here is just instead of returning this response we'll simply just return a redirect so we'll return redirect and in this case where will we go we will just go to slash home so now if i create a new user we would go to the home page uh and the user would be created so that's great for that but what i want to do now is have the ability to add a new field to our form so for right now all we had was those three fields but what if when you create a new user you want to ask a ton of different questions like a phone number you want to get all that kind of stuff how can we do that well to do that what we need to do is inside of our application here i believe we need to create a new file called forms.pi so what we're going to do is inside of register we're going to do new file we're going to save this as forms.pi and we're just going to modify our form slightly so save that as is there an issue this reason why this isn't working forms dot p y um hit enter okay i'm very confused right now why this is not working forms okay uh anyways let's try this one more time okay so for some reason i was just messing up but anyways forms.pi what we're going to do for this now is actually import these same things that we had before so this login authenticate user creation form so let's copy those and paste those in here and what i'm going to do now is just create a class that is that inherits from user creation form and add a few new fields to it so to do that i'm going to say class and in this case i'll just do register form and we'll inherit from user creation form and that means we're going to get all of the same properties as user creation form so we're going to have that nice layout as well but instead now we'll add a few new attributes so for example if i wanted to add an email here what i could do is i could say email equals and in this case uh models which i need to import as well so let me import this we're going to say from [Music] django dot models i believe import model it's either models or models any anyways so let's do that email equals models dot and in this case we'll say email field like that and this might be lowercase i'm not sure okay so we'll do email field there and now what we're gonna do is add something that we haven't done before which will allow us to change some of the parent properties of this class so i'm going to create a new class inside of this class which is called meta now it needs to be named this and what i'm going to do in here is define the fact that this register form is going to save into the user's database so you know how when we did a user creation form.save it save the form well we need to say that when we're using this form we need to save in the user database so to do that i need to import a few other things so one second here what i'm going to do is just go to i'm going to say from django dot contrib.off dot models and in this case import user and actually i need to change this django.models thing up here because this is incorrect i'm going to say from django import forms and instead of models this is going to be forms my bad on that so we'll say email use forms dot email field and then inside of this meta class what i'm going to do is say model is equal to in this case user so i'm defining that we are going to change the user model whenever we save something in this this form so now i'm also going to define one more property which is going to be fields now what this fields property is going to do is pretty much lay out where i want my fields to be so typically when you sign up you ask to do a username and email a password and the other password well right now if i were to actually use this form this email field wouldn't be showing up and that's because inside of the parent class it doesn't know that we have this email field so i have to define that so to do this what i do is i simply type the name of the fields inside of this list in the order that i want them to appear in my form so if i wanted email to show up first i would type email if i wanted a username to type up first i would type username so in this case let's do username email and then we'll do password1 and password2 now these three field names username password1 and password2 are already built into the form so this user creation form that's why i'm using them if we were to per se create another field here maybe we created a field that was like your gender or something like that then we would have to put that field in here as well if we wanted to show up on the form and this will specify in what order we want things to show up so that's how you can change that as well so now that we've done that we need to now start using this register form rather than using this user creation form so if i go in my views.pi file now i can actually remove this what i'm going to say is from and in this case we can just import it directly from forms so we'll say from forms import and in this case we'll do iso is register register form like that and now rather than using user creation form we'll use register form like this and this should be working for us assuming i did not make any mistakes so register form so now let's try to reload the page and see what we're getting on um what do you call it let me make sure that this actually is running quickly is it seeing that we changed anything uh one second guys uh no module named forms interesting i have forms.pi right here let's try from dot forms and see if this works there we go so i just need to add that dot before form before forms okay so let's go now back to uh what was it register like this and see what we get now okay so now we have username email password and password confirmation now i know this is still very messy but we have successfully added an email field so now it's time to actually make this look a little bit nicer using a little bit of bootstrap and what's known as crispy forms so crispy forms is a really popular form kind of framework used in django and you just have to install it using pip so what i'm going to do is simply go into my command line here and do pip install and we're going to say django hyphen crispy hyphen forms like that so not equal sign that needs to be a hyphen and what this does is it has some automatic styling for our forms it's really easy to use so that's what this module is essentially so we're just going to pip install that same way that we installed django and just make sure that it's in your virtual environment now you can see i already have it installed but once you have it installed there's a few steps we have to actually use this so to use crispy forms what we need to do first of all is go into our my site settings file so we need to find my site my site and go to settings.pi and we have to add crispy forms into this settings.pi file so to do this what we're going to do is we're going to say crispy i think it's just crispy underscore forms we i'm pretty sure that's all we have to do but i will double check here because i'm likely incorrect um let's see here nope that's actually correct so crispy underscore forms and what we also have to do is go down to the bottom of our settings.pi file and we have to define what um css layout or i don't know framework that our crispy forms is actually going to use so to do this i'm going to say crispy and in this case underscore template underscore pack and in this case i'm going to say boot strap 4. now if you want your crispy forms to use a different kind of framework css framework you can just look up how to do that online it's very simple but you just change this the reason i'm setting this to bootstrap 4 is because by default it uses bootstrap 2 and on our website we're already using bootstrap for so we might as well just use it now okay so now that we've done that we're actually have to start using these crispy forms that's what they're called so since we've had them uh imported into the project and we have everything set up all we have to do to use our crispy forms is at the beginning of our what do you call it file here it actually doesn't have to be at the beginning but it just has to be before where we use it what we're going to do is we're going to use our crispy forms so i believe to do this we have to say include something i have to have a look because i forget how to do it ah it's not included it's load so load crispy uh underscore forms like this and in this case underscore tags now all we're gonna do to use this crispy form very straightforward is we're just going to put this little up uh what is it straight line here bar i don't know what it's actually called if someone knows comment down below and beside it we're just going to do crispy like that now what this does is it's actually a filter and i'm not really going to talk about exactly what filters are but if you know phil what a filter is then that's what this is doing it's just going to modify our form to make it look a little bit nicer and add a bit of styling to it so let's try this now and see if everything is actually working so let me run the server see if we get any issues or not no we don't so now let's refresh this and let's see the drastic change that is about to happen there we go how much nicer does that look than our other form right we have username email password and password confirmation that is just much better and you can see if i go register it's still doing this so that is essentially how we create a register form for our users to create new users now right now it'd probably be a good idea to add like a bar on the side to do register and all whatnot uh but for now we're just going to leave it at this in the next video what we'll do is talk about logging in using these users and all that kind of stuff we might add a little bit more to this register page but for now i think that's fine and with that being said that's going to be the video i hope you guys enjoyed if you did please make sure you leave a like and subscribe and i'll see you again in another one so in today's video what we'll be doing is talking about logging in and authenticating users i will also show you how we can only restrict uh pages so that users that are logged in can see them so for example we maybe don't want a user that's not logged in to be able to create a new to-do list or because that probably won't work so how we can do stuff like that and then in the next video i'm going to be doing is talking about creating a custom user model which means that we can add things like all of our to-do lists to a specific user so that each user has their own to-do list and when they go on the website they're going to see different to-do lists not just all the ones that have been created by any user that's we'll be doing the next one but this one will just be logging in validating and logging out as well so what we actually need to do first of all when we're going to be logging in and logging out is we need to create those login and log out pages now luckily for us django actually does a lot of this work for us they have a built-in application if i show you in settings.pi here that is django.contrib.off and what this does is it authenticates users so we've done all the hard work of creating new users but now since we've done that django can actually authenticate those for us so we can use some of the built-in things in this application to do that for us so the first step in what we want to do is we actually want to use some built-in pages that django's made so they actually have made log out login um what is it change password like a ton of different pages like that that we can access uh simply by linking to them in our url patterns from our main url's file inside of my site so what i'm gonna do just like i've done to get into my other applications i'm just gonna say path in this case include but in here i'm going to say django dot contrib dot auth dot urls and i believe that's correct but i will check that quickly to make sure i didn't mess that up uh yes so that's correct so what this will do now is it'll go to this application it'll look in the url's file there and we'll see if we have a valid url so if we have login log out change password create password a bunch of those different pages right now we're just going to work with login and log out but you know what i mean so that's what that'll do for us but the thing is these uh views if we try to go to them now they actually don't exist so what those templates attempt to do or what the views attempt to do is render a template called login.html logout.html from a specific folder that we need to create so what we actually need to do and it doesn't really matter where we do this but i'm going to do it from inside of my register application so inside of templates i'm going to create a new folder and in here i'm going to call this registration like that now it's important you spell registration correctly like i just misspelt it registration because it's going to look for this specific folder so we're going to create a registration folder inside one of our templates folder and then in here we're going to create a new html file and we're going to call this login.html now this is gonna be where django will look uh and what template it will use to render our login form so what we'll do is we'll simply just do what we've done before so we'll start by extends um and then in this case main slash base.html and then we'll add our blocks for our title and for our content so let's do that now uh block title and then we're gonna say end block like that and then i guess we can do the title we'll just do a log in here or something like that and then you know i can just copy this and we'll just change the name to content and now we're just going to create a nice form in here that will display our form just like we've done probably four or five times by now so we'll say form we're going to say method equals in this case post and then we're going to say class equals in this case form hyphen group now we can end our form like that and then inside here we'll add our csf our token or whatever that is csrf underscore token and we will simply display our form now i want to add this to be a crispy form so it looks a bit nicer so to do that we'll have to load in our crispy tags so we'll say load and in this case crispy underscore forms underscore tags i believe that's the correct way to do that if you don't have crispy forms installed go back and watch the last video because we did that there and then what we'll do is we'll add a filter here and we'll say as the filter will just say crispy and this will display a nice form for us now we also need to add a button into our form because that doesn't come with it so to do that we'll say button we'll say type equals in this case submit and then i guess we'll say class equals btn vtn hyphen success and and our button and just say login as the name sweet so that should be it for this login form now we actually may want to add one more thing because sometimes you go to a login page that says well rather than logging in like create an account if you don't have one so maybe we'll add that in here quickly just make things look a bit nicer so we'll just add i guess some p tags and i'll just say slash p and i'm gonna say don't have an account question mark create one and then i'll add an a tag which will just link to our create so i believe it was slash register we did was it slash register create that was that url let's check inside of where is it here uh register register is the name awesome so let's go back here register and we'll say here and then slashing sweet so that should actually be it for the login page and now we can actually go ahead and run our server which i already have running and we will see that the login page is actually working so this is the logout page let's go to log in and see what we get slash login um oh well if you spell extends incorrectly extends there you go then it won't work now let's try it if i refresh this here there we go so now you can see that we actually have a nice login page and this took us all of what uh six minutes to create so it's pretty straightforward and what will actually happen here is this will properly do our logins and validate users for us so let's try to log in this is a valid login right now password1234 when i click log in you can see that it's actually directing me back to the homepage now the reason that this is happening is because i actually have something added down here in my settings.pi file that i forgot to like re-save that was telling us to redirect that page but let me just refresh this let me go back to login and do this again because i want to show you what happens if you don't have that you can see that it brings us to this note page not found which is probably what you guys are getting when you're running this now that's because what happens is when we try to log in it's going to automatically attempt to redirect us to a page called accounts profile now we obviously haven't created a page or a url for accounts profile so what we need to do is we need to modify where we're going to go once we log in now the reason was happening for me is because i had done that previously and forgot to save removing it but let's go inside our settings.pi file inside of our my site and let's add a redirect to let's say the home page whenever we log in so to do this i'm going to say in this case log in underscore redirect underscore url equals and in this case you can pick wherever you'd like to go but i'm just going to do slash standing for obviously the home page so let's do that now let's rerun and try to log in and well we will see that we should be directed directly to the home page once we log in let's do that and you can see we are brought to the home page so that's awesome now i'm just going to quickly move this up uh one because i don't like how that looks let's put this p tag just above here and now i want to refresh this and that looks a little bit better to me so sweet that's how we log in now let me show you what's actually happening in the back end when or how we can validate if we're logged in or not because right now there's not really any way for us to tell whether or not we're logged in or we're logged out so what i'm going to do is i'm going to go actually all the way back into my main application into templates and base.html and i'm going to create a thing that essentially only shows our main content uh body so like this block content if we are logged in otherwise it will tell us to log in and i'll leave a link that says login so a way that you can actually tell if a user is logged in or not is by using what's known as user dot is authenticated so i can actually create a code block here and i'm gonna make this an if statement i'm gonna say if user dot is underscore authenticated authenticated i think i spelt that correctly so what this does is by default whenever you go to a web page in django it has a user attribute which stands for the current user now if there's no user signed in i believe it defaults to what's known as an anonymous user so if you call user dot is authenticated on the user if it is a valid user that's properly signed into the webpage then this will return true if it does not return true then the person is not signed in so essentially i only want to show this content block for all the different pages that i have if we're logged in otherwise i want to ask the user to log in or even maybe redirect them to login so what i'll do here is now i'm going to put an else statement that'll say essentially else so if you're not logged in what we'll do is we'll literally just put an a tag and you guys can obviously make this look a lot nicer than i'm going to do and we'll just link it to the login page and we'll say uh log in here and you can just click this whole thing and that'll you know actually let's put this in a p tag make it look a little bit nicer slash p and instead of having the whole thing be a link we'll just do log in here all right so now we will hopefully redirect to the login page and the last thing i need to do before i forget is just end this if block so we'll say end if and there we go so let's now go back and let me go to home and i don't think i'm currently logged in but we'll see and okay so it is i am currently logged in so what i want to do actually is just log out so log out brings us to this logout page right that just says thank you for logging out this is the default logout page i'm going to show you we can change that in just a second so now let's go back to the web page and let's just go to the home page and you can see that now that i'm not logged in it says log in here if i click this um oh okay so that is actually an issue so what's happening essentially is when i go to the login page since we're not logged in it's not showing the login page because that's the block content so this is probably not the best way to do it but this is how you can tell if someone is authenticated so maybe actually let me remove this um yeah because it won't let us log in if that is there so we'll remove this for now and just leave it as block content but that shows you guys how you can restrict kind of page access to people that are logged in so obviously on certain pages you might want to add that if statement so that's showing different stuff based on if you're login or if you're not logged in but that is essentially kind of how you do login and log out i'll really quickly show you how to change the logout page if you'd like to do that so same thing as kind of changing the redirect here for login so what we'll do is we'll just literally copy this and change this to log out underscore redirect.url and then here we can just define whatever page we want to go to when we log out so if you had created a logout template you could go to that you could go to essentially whatever you want but just by doing that i'll just leave it as a homepage for now but you know you get the idea so i guess the last thing i'll show you is let's say that you create some urls inside of your new application so maybe we go we have a url we have to create so let's go to the create page for a second i actually want to go to views my apologies if we want to get the user from with within code we don't want it just inside of the html file what we can actually do is we can type response dot user now when you do response.user that will give you the user and you can run dot is authenticated you can get all the attributes of the user like the name the password the email all that stuff directly from the code and then obviously you could pass that into the context of the page or you could do whatever you need to do with it from the back end so i just figured i'd show you how to do that quickly so anyways that has kind of been it for logging in and logging out pretty straightforward in the next video we'll create a custom user model and we'll talk about how we can modify that model to add attributes like all the to-do list to a specific user so anyways that has been it for this video i hope you guys enjoyed if you did please make sure you leave a like and subscribe and i will see you again in the next one now i know i said i was going to be doing like custom user models here but the thing is to do what i wanted to do i actually don't need to use those and they're way like they're they kind of over complicated so i figured we'll just do it the pro like i guess the proper way or the way you're supposed to do it and then if you guys need to look up how to do custom user models it's not like super hard but just go online there's a few decent tutorials for that because i don't think i'm going to cover that in that series unless you guys really want that and you leave that as a comment down below but anyways the goal of this video is to make specific to-do lists for specific users so that when different users log into the website they see different to-do lists just like you know if you're on facebook you're gonna see different posts like stuff like that right so it's gonna be a little bit more custom to each user and obviously they can save their own to-do list and that'll be saved just for them and other people shouldn't be able to view that so what i'm going to do and i need to do this is inside of our model stop pi file inside of our main application i'm going to just add a foreign key to to-do list which is user and then that way our users will have a to-do list set where we can view all of the uh the different to-do lists with that user so to do this i need to start by importing our user model so to get that i'm going to say from off django.contrib.off. models import user with a capital u now what i'll do is just add a foreign key i'm just going to copy this and just change the names here instead of to do list we'll say user and we'll do user right here so we'll have user models.foreign key so now we're saying that essentially every to-do list we create will be linked to some kind of user awesome so now uh what we need to do is actually make some migrations in our file so that uh we're gonna update our database accordingly to that now you shouldn't run into any issues doing this uh it should just like create the migrations for you but if for some reason this doesn't work what you need to do is delete all of your database files so delete your database file delete all of the um everything inside of your migrations folder including the pi cache but not the init.pi files and that goes for all of your migration folders so any migration folder delete everything except this init.pi and then anywhere you see a pi cache folder delete that and that'll allow you to do the migrations after that so now that we've done that what do we need to do next well now when we create a to-do list things are a little bit different so this is where we're creating a to-do list and what we're doing to do that is just creating a new to do this and saving in the database but now we need to save the to-do list to a specific user so to do that what we're going to do is we're going to say response dot user dot to do list underscore set now i don't know if this is going to have to be capital or not so we'll have to play with that in a second but i think it should just be like that dot create and in this case we'll give a name to our to-do list and we'll say the name is going to be equal to n now i believe this is how you create it i'm gonna go look to see how we created the item yeah so that is it's a similar way so we'll test this to see if that's working but this should now be saving our to-do list to a specific user now we can still access our to-do list by doing the slash id of those to-do lists but we're going to probably modify this a little bit so that you're only able to access uh to-do lists that are yours so that'll mean we'll look at the id and then we'll see if that's in the user set and if it is then we'll show that otherwise we'll say like you don't have access to this to-do list or something but let's first just make sure that we can create them okay so another thing that i'm going to do actually is we've created this uh if i go to templates we've created um no we have not created but in our base.html sorry guys we have this slash view here right and this originally i think i had it linking to two just to test stuff but what i want to do is actually make this go to a list of all of our different to-do lists so i've created this slash view so now what i'm going to do is i'm going to add a url inside of our urls here that is going to be slash view and what slash view will do is it'll bring us to a list of all of our to-do lists so i'm just going to say the function name will be view the link will be view and the name will be view and then what we'll do is we'll create a new i guess function inside of views.pi and we'll say define view response and then what we're going to do is we're going to return a render of in this case we'll say response view and main slash view dot html and then we'll pass in nothing as the context so now we've done all that we actually need to create a view template so i'm just going to make a new file and i'm going to save this as view.html and i'm just going to extend this from the base template so extends base dot main slash base dot html and then we will add our blocks so we need that block for the title so we'll say block title like that and then end the block so percent percent and block and then inside here i guess we'll just do like view and then we can copy this and just change the name to uh to content so con content like that and then inside of here what i'm going to do is i'm just going to create a for loop that's going to loop through all of the different to-do lists for our user and display them it'll be very very basic but we can obviously modify it later so let's add a for loop so say 4 and in this case td which is stanford to do list in this case user dot to do list underscore set then what we'll do is we'll end the for loop and n4 and then in here we're going to create some links to all of our to-do lists and display them just in little paragraph tags so i'm just going to say p and in this case we'll add the name of our to-do list uh yes we'll add a link here so we'll say a we'll say href equals in this case slash and we'll say td dot id and then we'll end that a tag so slash a and then and the p tag slash p and here we'll just put the name of our to-do list which in this case is simply going to be td.name all right so that should display all of our to-do lists in just like a standard i don't know like list kind of form we could make it look nicer but for now we're just going to go with that and yeah and then we should be able to click on them to access those to-do lists so let me see if this is actually working so let's run the server any errors let's see uh no errors so let's now go back to here and say i'm going to create let's just go to the home page and let's go to view okay so if you are not running into any issues we're obviously not seeing anything so now let's try to create a to-do list so if i say tim create new and we run into an area no attribute to do list underscore set i thought that was going to happen so let me see now if we need to add the capitals to that or not so inside views to do list underscore set maybe that's the issue i don't know we'll see though and then i guess we're gonna have to change inside of our vue.html file to be capitals as well now if this doesn't work i'll quickly do a little bit of research and figure this out but let's try it now and let's go back to slash create can continue has no attribute to-do list underscore set sorry i'll be back in one second guys with the proper attribute name for that all right i am back and with a ton of errors that i had to fix so essentially one of the first errors is we need to go here and change this to be user.to-do list.all because i was trying to loop through something that's not iterable because this is a different object so just to put this all here you don't need the brackets after and leave this as lowercase to-do list and then we need to do is go to models and we need to add these two fields to our foreign key so we have to say related name we're going to find this as to-do list and then null equals true now essentially the related name is going to be the way we access this from the related object which is user so we just change that to to-do list we say no equals true and then what we're going to have to do to save that is make migrations you know python manage up high make migrations python managed up high migrate you do that you should be set and then the last thing we have to change is inside views.pi is what i've done here is i've created a new to-do list so i said t equals to-do list name equals n exactly what we had before same thing with saving the to-do list except now i said response.user.to do list dot add t and then we can still link back to that id because that id is perfectly valid it still exists so we can see that and everything works fine so that is the fixes that's what we need to do remember that once you change these this models file by adding the related name and the nil equals true you need to make migrations to save those changes and then rerun the server so i'll show you now what it looks like so essentially you can see i have two to-do lists that say hello when i go i can add items to the to-do list so let's say like item one add item there you go we can check it we can save it all that fun stuff if i go to view um it should be showing me this but for some reason that's not happening um let's see here let me try logging out and logging back in so let's say slash logout and let's say slash login let's go tim password sign in view and there we go we can see that we have now these popping up so we have to be logged in to be seeing these if we are not logged in we are obviously not going to see anything because we don't have any of these so now let's try to create another account and add some of our to-do list to that account and then see if it's different than what we have before so let's say we're making a let's say the email is bob techwithtim.net let's say the password is the password i've been using consistently and there we go let's hit register all right so we don't need to save that but now let's go to view and we're still seeing hello twice which is interesting to me oh it's because we're not logged into uh that account so let's do slash login and then what we'll do here is we'll say bob and password and log in and go to view and obviously there's nothing there so let's create a new to-do list let's go new list create list let's go to view and now we can see that we have new list showing up and that is working now i'm sure this is fairly buggy but this gives you an idea of how you can add things to specific users so you can see them on the web page now obviously we can make it so that you can't view other people's to-do lists because for example if i go slash 2 i can view the hello to-do list even though that's not mine so we'll quickly do that and then i guess we'll probably wrap up after that so let's go to index here now and let's quickly say we'll get the to-do list um objects we'll gets we'll get the to-do list as an object and we'll just see if that to-do list is in the users list if it's not then we'll just you know get out of that we won't let this happen otherwise we'll do whatever we already have so we'll simply just say if in this case response dot user dots i guess to do list dot all like that but we'll say if ls in that then this is valid otherwise so we'll tab all of this in otherwise we'll simply just return we can either give an error or we could just like not let them go to this page and to do that we can just link maybe to the home page or something if they try to do that so i mean you guys can pick what you want to do there but i guess i'll just going to ring a link to our home page here so we'll just link to home dot html and we'll just say in this case or actually maybe let's instead of going to home let's go to view dot html because then that way they can view their to-do list so maybe that makes more sense so now let's try this so let's try to go to two now refresh and you can see that now it's simply bringing us a new list because well that's not our to-do list so if i go to three you can see new list is valid because that's our to-do list so we're able to view that now this is probably not the most secure way to actually like hide information just with like this if statement and all that but i mean you guys can mess with that if you want and this is a very very basic example so anyways that is kind of been it for how to add the to-do list to specific users how to see that i know the login and logout system isn't super smooth right now but you can obviously add that on the side my main goal with these tutorials was to give you guys kind of the starting blocks on how to do things ideas on how to go about stuff i really can't show you possibly everything because it's an infinite amount of stuff that you can do with django and with that being said i will hopefully be doing a deployment tutorial soon it probably won't be for the next few days but at some point i definitely will do one and i encourage you guys to remind me and get on me if i'm not doing a deployment one because i will do that at some point and that has kind of been it for the actual writing code and all of this of the django tutorial so i hope you guys enjoyed if you have any questions or future videos you'd like to see please let me know in the comments down below and i guess i'll see you in the next [Music] video
Info
Channel: Tech With Tim
Views: 163,955
Rating: 4.9401422 out of 5
Keywords: tech with tim, django tutorial, python django, django tutorial python, python django tutorial, django web framework (software), django setup, django setup windows, django, python django web development, django website, learn django, django for beginners, django python, django python tutorial, django python tutorial for beginners, django python web development, what is django python, django python database example, django code, django development, django python development
Id: sm1mokevMWk
Channel Id: undefined
Length: 193min 54sec (11634 seconds)
Published: Sun Mar 21 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.