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.
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.
So how do you have to do it?
Let’s go with the practical part to make you understand clearly & easily.
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.
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.
And then you have to show that form on the browser.
So your form will look somewhat like this.
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.
Which Tag you have to take?
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.
What will we do here?
We’ll take Center Tag here.
And I will close this particular Center Tag after the form here.
Now I gave a heading under the H1 tag.
For instance I gave a heading named HTML Form.
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.
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.
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?
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.
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.
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?
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.
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.
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.
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.
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.
Let’s meet in the next video.
Django's form also makes it easier to create a form that feeds data into a database table. Django forms make it simple to move data from a form to a database table. It's easier to use basic HTML forms when designing any type of sophisticated form with complex styling.
The standard forms HTML is auto-generated for you with Django forms, and you only need to enter code where you wish to alter the form. Django forms also take care of form validation, which you can alter with self-written code only if you need something exceptional.
Forms allow users to submit data that is either sent to a web server for processing and storage (see Sending form data later in the module) or utilised on the client-side to alter the interface in some way immediately (for example, add another item to a list, or show or hide a UI feature).
The FORM element's action attribute specifies where the form data should be sent, while the method attribute specifies the HTTP method.
where will i get code access for the project source code?
this course structure is very good. I suggest for learning to this website.
Superb and amazing 😍🤩 enjoyable experience.
Er Komal Gupta
thnku so much sir. after waisting so mch time in boring videos.i learned only from here.explained vry well and i will suggest evryone that learnvern is the bst online plateform where you can learnalot
ajax lesson was something like boring . But , learned a lot with the sunit sir . Just learned how to deal with ajax in django