Hello guys. Welcome to LearnVern.
In the last video we saw how we loaded the template on the browser in which we created a template folder, created an application folder in the template folder, and then we created an HTML file, which after rendering it through View, we showed it on the browser in Django.
Today we will see how to create forms in HTML, right? That too in Django.
Clear?
First of all, I will explain to you what form means.
Form is used to collect data from the users in the HTML, right?
And when you have to send that particular data to your database, to your server’s side, you will use form only.
Without form, you cannot send data on a server.
How will you create?
First of all, form is created through Form Tag in HTML, right?
Without Form Tag, you cannot create any form in HTML.
Right?
So how do you have to do it?
Let’s go with the practical part to make you understand clearly & easily.
Okay?
Here we have the set up of Django project.
What do we have to do now?
Right click on the Application folder, you have to create a New File.
Suppose I make forms.html, right?
I made a whole structure named HTML 5.
Okay?
This is the best thing about VS Code that just as you write HTML 5, it will make you a whole HTML Structure.
Now what do you have to do here?
You have to create a form now.
Okay?
And then you have to show that form on the browser.
Right?
So your form will look somewhat like this.
Clear?
We want to show a form like this on the browser.
How will we do it?
Let’s do it.
First of all you have to take Form Tag.
Okay? Right?
Which Tag you have to take?
Form Tag.
In which certain attributes will pass.
Further in which there is Action, what does the Action attribute do?
It tells you on which path you have to take your form’s data, which means on which server path you have to take it on.
And this method, okay, there are 2 methods, Post Method & Get Method.
I’ll explain them in the next video due to which you will get a clear idea about what Post Method & Get Method do.
First of all we will learn how to make a form.
So I took a form here.
Now I have to take that form into the Center Tag, the form should be in the center.
Right?
What will we do here?
We’ll take Center Tag here.
And I will close this particular Center Tag after the form here.
Okay?
Now I gave a heading under the H1 tag.
What?
For instance I gave a heading named HTML Form.
Right?
So this is our heading.
Now I have to make a particular form here.
How will I make it?
So for it to look like a particular systematic form, we will have to use a table, okay?
In the table, first of all comes Row, okay?
TR means Table Row. okay?
Further in Table Row comes Table Data, means TD.
Right?
Suppose I want the first name of the user, right?
And what do I need for the first name?
I want input, which means a text box.
For text box, I further took an input, a TD, that is a Table Data.
And then for input, I took Input Tag.
I made a whole Input Tag here.
Right?
In the same way, I’ll copy TR and paste it multiple times here.
Why? Because I want multiple fields.
I then took Last Name here.
Then I took Email here.
And lastly I took…Contact here, right?
Clear?
And then I took one more TR here in which I kept only 1 TD and in that particular TD, I took an Input here.
Why?
Because I want to make a button here.
So whenever you make a button, to make the button, what type do you have to put?
You have to keep Submit.
Okay? If you keep submit, your button will automatically be made.
And if you want to show any name on the button, you have to use Value, right?
Suppose I wrote Submit here, okay?
So our form is ready now.
Right?
Now for instance, I want to call this form.
How will I do it?
I had told you in the last video that if you want to render any particular template, how will you do it?
Go to Views.py.
And make a function Def html.
I made a view named htmlform & passed a request here.
And return render request, app/.
What is our template’s name?
Forms.html.
Okay?
So this is how you have to give the path in this manner as I had shown you in the last video.
Now what do we have to do?
We have to make a URL here, okay?
How will we make a URL?
First of all, we will open urls.py in your app, and then we will import our views.
Right? Clear? Okay?
And then path, then views, okay.
Why did we leave the first part, the double inverted commas blank?
Because we have to send a request directly on this page.
And then the htmlform view we made.
Then Name = I’ll keep htmlform.
Okay?
Right?
So what happened here is, we made all of these things, right?
Now what do we have to do?
We have to run our server first on our browser.
Let’s go where it is.
We’ll open CMD, right?
Then our virtual environment activate.
And then we’ll run our server.
Okay?
We ran our server.
We will copy this link.
And then we’ll go to the browser and paste it there and run it.
Our particular form is ready in which we took 4 fields, and took a particular input.
Okay?
So this is how it is made in an HTML form.
Okay? Right? Clear?
Hope you understood how we have to create an HTML form in Django.
Okay?
And if any of you have any doubt, you can go to forums.learnvern …
If you have any queries or comments, click the discussion button below the video and post there. This way, you will be able to connect to fellow learners and discuss the course. Also, Our Team will try to solve your query.
When we move further, what will be our next topic?
What are forms methods and what are ORM queries method in Django.
Okay? Right?
Let’s meet in the next video.
Share a personalized message with your friends.