 What we can do is we can also look at an example of a form so we can we can create a form to enter the book or the member So I'll go back to our chat session and I'll wait for someone to Ask any questions if they have Anus he asks if I can remove one two three in the list of books If you want to remove one two three then you need to use an HTML tag called UL or unordered list and Then your your ally will look like a bullet point instead of a one two three number So you can look at a camel tags and sort of design your HTML. Anyhow you want He may be I'll stop sharing my screen and you can remind me to start sharing it later on but You can share your screen and tell me why your browser says name error It is probably something to do with the wrong syntax I will ask and please ask your question out loud so that I can answer No, can you please show me the error in your open your terminal where your server is running that is where you see the error Yes, so it says name book is not defined So the reason for this is you're not imported books in your views.py If you're not imported it your view.py file does not know what books variable means Which is why it cannot understand Dr. Kulkar me if books is only books is displayed and if list is not displayed that means your database does not have the book data Please go to your admin dot your admin URL Please log in please enter some data into your admin or URL which file No, go to your browser open the admin URL flash admin flash admin and Please enter some data there so that you can see the data on your And please So Smith is asking can we create a form in slash form and then show the accepted entries in books? Yes, we can do that. So that is the next sort of Next exercise that we will be doing for the next half an hour one hour or so So someone has asked can we did not create description in the code, but we wrote manually with our super user access Can we display it in the books list? Yes, so we we have the full book object the book object that you query and have stored in all books Contains all the data related to those books. So you also have the description data in your template if you go and The place where you have written book My book you can you can write my book dot description and it will print out the whole description of your book Like I did for author you can do it for this you can say my book dot description So what we can try now is we create a form so So like I mentioned are in my yes Sir after creating the member in the web browser. I have not wrote the code, sir Okay, so in that case unfortunately, we've gone little more ahead. I can't reverse all the way back to the point where you are at The repository shared with you has most of the code If you can figure it out, you can copy paste parts of it and try to make sure that you are as far So I will try sir So what we did I explained the whole workflow of how your request goes and your response which is back For the current books example what we did was we send a get request when we sent a get request What we did was we didn't send any request from the client to the server What we did was we asked the server to send us some information So that is what a get request is you're getting some information and you're not sending any information So you only ask for information. So again There was some database interaction, but The information was uni direction. It came from the server towards your client In in most of the cases this is not the case you need a more interactive website where you can submit some information and That will get stored on your database and then you can do some more thing, right? So when you're sending information from your client to your server It is called a post request When do you do a post request when you're sending some information from the client and want to edit your database or make changes to your database? That is when you send a post request The most common utility of a post the post request is just an STTP protocol It's a part of the STTP sort of request protocol but the Most common method to sort of the most common time or the most common place where this post request is used Is when you are submitting a form on any website? So any website that has a form basically when you click on the submit or the add button So when you're filling When you're filling your college application when you are filling the train Ticket reservation, etc. You are sending a post request What that does is it is sending information from your client to the server and the server is then behind the scenes adding some information to the database Right after that also the server will get some information and it will send it back to you So let's build a very simple form We'll not do anything complex. We'll build a simple form that takes the book as input and stores a book to the To the database, all right Let's start For this what we need to do is share the screen sir Thank you To show up in some time Yes, sir showing Okay So now what we'll do is we'll be creating so there apart from you are as views models and templates Django also has an an inbuilt structure for building understanding and parsing the incoming data from a form submission Right, so it is very conveniently called a forms dot py file any forms dot py file in your Django application stores all information related to the post request forms that are being handled by your web application to be able to create a form dot py file First go to library manager app folder So the folder that contains models dot py Etc. Please go to that folder and create a new file. Let me check if it is already there Should not be there Yeah, so there is no file currently called forms dot py because it is not a default Feature, I mean it's not something that's very common would only use it in certain cases So that is one file that Django doesn't create for you by default But you can always go and create one right so I will create one just from here Please use any Any method that is convenient for you To create a forms dot py file. I'm using the command line You don't use these commands in your windows, but they not work It should be forms dot py f o r m s dot py Please create it inside the library manager folder not anywhere else if you create it anywhere else It will not work Right. I created a file It will now show up in my in my My spider interface. I'll open it here and it is obviously empty Because it doesn't contain anything But it is not recognizing touch It will not recognize that sir. I already told you in windows There is no command called touch, but it will not work for you Please create a new file by going to windows explorer or creating a new file, whichever way you think is comfortable I think I don't know spider allows you to create files. I don't think it does So please use windows explorer or any way any Way that you feel is comfortable for you to create Please create the file. Please make sure it is in library underscore manager Please make sure that you have put it in the correct library manager folder This is the library manager folder that contains the models dot py and abuse dot py etc Please do not touch any other file Please save it correctly How to create a new file there like going to new then new folder option is coming text document Don't use spider. Please use windows explorer if you I mean please use Any way that you'd use in a normal computer setup just use that so I guess you'd use windows explorer right windows And you create a new file Go to the folder and windows explorer right click. There should be a create new file or a new file option Please try that Okay, hopefully everybody is done by now in case you aren't just say no in chat and I'll try to come back to you But otherwise, let's go ahead with though Honestly, I don't know what you did But as long as you saved it as forms dot py is fine It should show up as forms dot py and it should be inside library manager in the same folder where models dot py Right Okay, right So what are we doing? We are creating So we are creating something called a model form What do you want me to repeat? Please create a forms dot py file inside the library manager app folder The library manager app folder is the same folder which contains models dot py There are forms dot py file should be a new file created in the same folder where models dot py is located Please check three times that you are in the correct folder before creating the file The file should be called f o rms dot py and once created open it and wait for the next instance That is what we missed out okay, so We first need to import a utility Class called model form a model form is basically a class that allows you to automatically create a form and Create the necessary tools of the form from a existing model. So we already have the book model So we use a model form to get all the properties of the book model as a form in the format of a HTML form right a submitable form we use from Django dot forms import model form right We will then import the model itself. What is the model from? dot models import book The book model should be available in model dot py right, so please check that model is available You will now create a class for the form so because the class relates to a form So the name should be relevant, which is why I'm calling it a Very interesting name called book form It will inherit from the model form because the model form has the inherent properties that create that allow you to do a lot of Use a lot of its inbuilt features The model form will not have much details inside it. It will have another subclass So you can define a class within a class or a method within a method In this case, you will define a meta class The meta class will contain two attributes The attributes will be model Equal to the model name book If you also contain fields fields will be all the fields so If you do if you want all the fields You need not specify this particular variable if you want to control which field you want to display You can define this variable But for now since I already said that there's a attribute called fields. We just add all the variables here Where is my model dot py Because I forgot what the fields are I till author name is be a number genre and description we'll add the field name as string I tell Of her name ISV and num genre and description Now, please make sure that the variable names are the same the spelling is correct The variable names should be exactly the same as the variable names of the fields in the model file Any difference here will lead to problems or errors Title author name I'll be number genre and description. So five feet, right? I will save this Unfortunately, you can't see the whole file, but I'll keep this here and please copy it and I will I Will keep monitoring the chat in between sorry please type this out please Copy this out type this out This particular form dot py file is not available in the repository the repositories taking a slightly different direction in terms of the Database design so that will be slightly different. This is not there in the GitHub repository So please don't copy paste from GitHub Please just type out what I just type Please keep the spelling names the same So Smith has asked can't we use all all is a ORM query method name We don't want to run a query here We just want to design a Submitable form. So this is going to be the object that gives you the form Layout on your HTML page and we'll show you how There is like you can pass So So but currently I think it is better We need to create a view because this is now going to be a separate logic or business logic where we want to show the form, collect the data, get the response, etc. This is going to be a completely new template and view because we will be hitting a separate URL. So let us design a new view. We will call it depth new book. We will pass it the request argument. We will do a couple of things here. We will first be checking if the incoming request, so this is a request object. This request object is the same object that I talked about earlier. When you are hitting the URL in your browser, your browser is sending in request. The request is then sent to this function, this view function as a Python argument. It contains all the information that a request should contain. It contains your source URL. It contains the timestamps. It contains your computer's IP address. It contains the surprising amount of information and that is why websites start collecting all these kinds of data from you. That is how they do it. They get a lot of information by default. You want a simple application like this and collect a lot of information about you using the request that comes in from your computer. You have the request object. You will first check if the request is a post method or a get method. Like I said, a get method is a simple URL calling your browser. A post method is a submit action or a post action from your browser. It will be sending a separate post request. A get request and a post request are different. You will be able to check if your incoming request is of a particular type. You will do request dot method equal to equal to post. Sorry, capital post. So this checks if the method of the request is post or not. Here you will create an instance of your form. So you will say form equals book form and you will add the request post data. How will you do that? You will say request dot post. You may not be able to follow along with all the variables that are here but please understand that these are inbuilt variables and methods. They are getting you all the request related information. Your form needs all this information because it is going to at times it will also pre-populate certain information in the form itself. So that is why you need to send the information to the book form object. Once you generate this form, you will check if the populated information that you got from the post request is correct or not. If form dot is valid, you will do a form dot save. So what is this doing now? You have populated your form object with the post request information. Django internally has a very convenient way of checking if the data that you sent in is correct. Does it follow all the data types that you defined in your model? Is the book name correct? Is it following the character limitations? Is your number correct? All these validations are done. All these checks are called validations. These validations are done and then you can save your form object. Saving your form object simply means that the form data is transferred to your database and a model object is created and then the model object is saved into your database. This is the shortcut way of saving your form information to your database. So as everybody has very correctly pointed out, I have not imported anything. So I will add an import statement here. From dot forms import book form. Again, just to reiterate, please make sure that the names, spellings, capitalizations, small letters, capital letters are all correct. Otherwise things will not work as expected. Now once the form is saved, your view function should also understand what should happen next. So if you save the form and if you see the same page, then you are going to be confused as to whether what happened. Did my form get saved? Did my book get saved or not? So to sort of indicate that your form was successfully saved and you now can go back to your regular life, we will redirect stuff to another page. Which page can we redirect it to? You can redirect it to books. Do we have a name for the URL? Yes, we have a name called books for our URL called books. So we are using this name. We are not using this or this. We are using the name argument to indicate which view you want to go back to. So this view function after successfully saving your form will automatically redirect you to the books view and it will show you all the books again. Because you want to see the book that we added in the list. We will do a form.save, we will do a redirect and we will go to books. Same way, we have not done an import for redirect. So please add redirect. Add redirect import in Django shortcut line. Now this is a process when you are sending a post request on an already existing form. But when you are visiting the page for the first time, you need the server to send you the form in the first place. If you do not have a form, what will you fill in? So for that, the request cycle is always that the first URL is a get request and then you will send in post request based on the form that you receive in a very simple request response structure. So if the request method is post, then do this. Else, if the request method is get, you do not have to specifically type out that condition. You will again initialize the form. This time it will be an empty form with no request post data because you do not have any request post data. You want an empty form and you will now return a render method. Your render like last time will contain a few things. What will it contain? It will contain the request, the request object. It will contain a new template. What should we call that template? We should call it form. So we have the library manager folder where we are going to create this template and we will call it form.html. Or we will call it book form. It is the same naming convention. We will call it book form.html. And we need to send it some context. So what is the context in this case? The context in this case is the form itself. Form, form. This is the form object. I will save this. In case you need some time to copy, please let me know. I will copy. I will keep it. Has everybody followed earlier? This was a slightly lengthier piece of code. So I understand if it will take some time. I can wait for maybe say 5 to 10 minutes and let you copy all of this. And we can then move forward. So what we will write in book form.html, I will tell you. But I need to make sure that everybody has already done this. Is it a curly bracket or some other bracket of the render? For render it is simple bracket. For context it is curly bracket. Yeah. Context is a curly bracket, yeah. Somebody asked why is context essential? So context is essential to send any data to your template so that your template can populate the variables inside the template with the sent data. In the books method, we had already had a list of books. In this method, we have the form HTML. And I will show you how it shows up. It is a form object. The form object is then rendered as a form in the HTML. I know I keep repeating form. So I will show you how it looks in the final file. So if you are already done, please recheck the type commands again. Please make sure that the indentation is correct. Please make sure that the spellings are correct. Please make sure that your post is capital. Please make sure that your path to your book form that HTML is typed correctly. There are a lot of indentations in this function. There are at least two levels of indentation. I can use spaces everywhere. The closing on the render bracket is correct because I had a lot of values and I can't show them in one single line because it gets too lengthy. So I added it to the new line. The alignment of the brackets don't matter. They should just be closed correctly. Obviously that does not mean that you can ignore indentation. So is everybody done? Can I move on?