Hello, friends, in this video, we shall see the form a tribute of the request object in a flask application.
When the e-mail form is posted or when inside the e-mail form, you give the different form, attributes
like matter is equal to is one attribute and action is equal to another attribute.
For instance, have a look at this line of the e-mail form from action is equal to this is where the
data is to be directed or said this is where you are and to which it is to be said and which is the
method to use the method to be used is written as that would of method is equal to in this case it is
being used as post.
So this is the beginning of the formal declaration and this is the end of the formal declaration form
between which.
Different form elements are used.
In this case, the former elements are nothing but just for text elements, are there input Irish politics
four times?
Do you see that they are being written in the name of the former element, is written by name, is equal
to attribute.
So name is the label.
Input to the text name is called the name.
This name is what the name of the family name is called Physics Chemistry.
And so therefore when this e-mail page is open, what will be rendered on the client browser, it will
just have a form of it for next week's each having a label like name, physics, chemistry, mathematics
like this.
And then at the end of that, the form there is a submit button so that when the submit button is clicked,
the form the will be redirected towards this.
You are it.
What is this you are which going to localhost five thousand with the two words that you are, it will
be redirected to use this post.
OK, so in order to process this data, what I would do, I have to define this URL and map that you
are all with a certain view function and that function will process the form data.
How.
Like this, this is the pattern you are defined as a result because that is where the data is coming
and the map of the function.
If the request documentary is equal to post, then what has to be done?
The data collected, which is where it is collected, it is collected in that we would call that request
not form.
That result is stored in addition to the object called a result.
And that dictionary object is used as a barometer to this render template function.
So this render template function will render this table that estimate and.
It will take up the reserve parameter, and that is barometer out process, that result parameter inside
the template code off, they will not estimate.
OK, so third parties, this template, remember that this table, that esteemable, should be stored
in a template for them.
So in that template folder, this table or the estimate, is that what it is doing?
It is just iterating over the result object with the help of IT writeups functions, it will form an
iterator over the dictionary object.
You know that the dictionary object is a collection of items and each item is having a key and value.
So for each key and value for this, it is starting a table.
And for each value of these key and value, those key and value of first items, second, third and
so on, all these items will be placed in a room.
So at the end, what you should see, you should see the table XHTML table being rendered on the client
browser with all those four parameters name physics, chemistry, mathematics and values such like they
will be generated when you execute this.
So what we have we have all these three components.
One is the form estimate form second and the third is the template.
So I'll show you these three ingredients of the code.
Put it on at one in one application folder.
Execute this Python script.
The server will run in, fill the data in the form and see that the table is generated.
All this we will see with the help of a practical example in front of, you know, using this example,
we shall now see how to send an e-mail form data to a particular you are, which is defined by the root
decorator in your application.
So to start with, you have to import all the required, you know, functions and classes.
As usual, you needed.
Import the flask plus.
Because you want to render the template.
The render template function and also import the request object.
OK, so this Python script actually has two rules, which are different.
One is this backslash you are in.
And the other is the result, you are Elwick.
The root function root matter, rather, while dividing these slightly children, also takes one more
argument, which is the methods, argument and methods have been or any of these two methods, subject
matter can be, uh, you know, applicable or acceptable to this particular.
It is Arturo.
Of which we are.
Basically interested in what happens if the metal is pushed so that.
Afterwards, initially, when the server starts and you gather you are in your browser like localhost
5000, slash the bone function here is in this case to run this interview function and then this function
is executed.
A student or e-mail template, which obviously must be present in the templates folder of your application,
will be rendered, what is this student body?
It is a simple form in which some data can be entered that we shall have a look at it afterwards.
Right, so start the server unit slash backslash, you are in this template, will you render it will
generate a form so the user will now enter the form.
So at this juncture, shall we see what is the form?
This is a simple form in which three text inputs are, you know, the reader input type you can to text
that, read the text box.
Three, not three or four, rather, one text box or name, physics, chemistry and mathematics, and
and then there are of course, there is a submit button.
So importantly, this all.
Input types are present in the form whose action?
Attribute is directed towards a you are in local fighters desert.
And the is pushed.
So this is as simple as you will see, a very simple, stable form that was created and this student
body is put into the templates folder.
Now, coming back to this Python script.
This is the result you are in, which is used as the action attribute of the former.
So what what what does it mean when you click on the submit button, the form will be posted to this
desert slash result, you are ill and since the scenes in those days will call you the mythological
post.
So the data will be received by this result.
You are in the post ometer, so the associated function you function is.
This will be executer this statement is true.
Requestor method is equal to post.
So therefore, what will happen?
It will fetch the entire data from the.
From.
Using the request not from.
Mr..
And what did we contain, it will contain all the farm data in the form of a dictionary object, and
that object will be called reserved.
Right.
So using this result dictionary object as a parameter.
The another template result, Estevan, which is also present in the template for folder, will be rendered
by this result function.
So render template result that e-mail.
What is there in the world today that we shall see, but it will.
The result of the e-mail template will be provided another parameter or attribute result is equal to
what it is.
This is the.
Name of the dictionary variable.
Rather, this is the barometer to be provided to that template and this is the dictionary object reserved.
This is the result that have been defined here.
So, in effect, what is going to happen as this of starts, a formidable display form will be filled
by the user submitted to this result.
And it will fetch the entire form data into the desert object, and that will be rendered to this Liselotte
estimate.
So finally, what remains what is present in this estimate?
So this is the result of a stable template starts with the mandatory DOCTYPE e-mail tag.
And this is the rest of the esteemable, this is what is the.
Ginge to templated.
Uh, you know, instructions.
So all those.
Conditionals, explanations and loop statements are used or written in this case, the curly bracket
and.
But since nine, on one hand, on one side and percent on the and the writing on the record in between
these, you are writing it for Luke.
And these four loop were result, not ITR items, what is it, what items it will fetch an iterator
for the dictionary object called isn't so it items from a third of the dictionary object is used to
return any tretter.
And you know that the dictionary object is a collection of items.
Each item is a key value pair.
So for each.
He will appear in the end result of what we are doing, you are just putting the value of key and value,
key and value are put into the.
Roll off a table in the first sale of the roll, your display in key, second sale of the role, you
are displaying the value.
So all the text boxes that you enter name physics, chemistry, mathematics.
The.
Names of the keys and associated values will be displayed in the table, so as a result, what you should
see, you should see a table being generated on your.
Brazil.
OK, so these are the three parts, one is the Python script, which is a flask sort of application,
second is the form and third is the template.
So let us see one by one how.
The result ultimately comes onto your browser.
So first, let me.
You know, started this battle group, formed DataDot Pivo, in which the two are slash and slash result,
are defined their bond with two functions one one first function is.
You know, displaying the form and the other is displaying the result.
Of the.
Formed a tie into a table, so start the server.
And go to the browser.
So the brother is.
Here and just you know, you are a local news veteran, backslash Delenda the form.
Under the data.
And.
Press the submit button, what happens, the form that will be posted to the result?
You are in the associated review function will fetch the form databasing request or form in addition
to the object.
And that dictionary object will be rendered by result of the activity in which there is a danger to
template code which runs so far.
Luban generates a table.
Like this.
And this is the final output of our entire flask application activity.