Hello, friends, in this video, we shall try and write our first flash application or less Hello World.
Hello, World is invariably the first program that you write whenever you learn a new technology.
So here also we shall see how to write or how to generate Hello World from our application.
First and foremost, you are to import the last module.
More specifically, you have to import the flask, a glass from the flask module that is mandatory,
then you have to instantiate or you go to create an object of the flask.
Plus that object of the flask class becomes our application object.
It is an object for our WGI application.
So these two steps are in the right in the beginning of your of our coal importing the flask Maryland
class class and creating the object of.
Now, you know that whenever an object of a class is instantiated, the constructor starts to work,
so the class constructor also will be executed.
And it takes one argument inside the underscore name, and it is the name of the current module that
is the argument for the object.
Then you are to use a function, root, root function of the last class is to be used to define the
new order and map a particular view, function with the, you know, use the rule.
So this root function is called as a decorator, which does the application which you are allowed to
be, which when a particular order is given, which is the function that is to be executed, that association
is defined by the root function.
So this is the way in which this rule function is used.
Eppy, the app, the name of the object of our Flast plus eppy, that route two arguments will be the
rule.
Rule is the other options are of course they are optional.
They may not be appearing every time Ruri parameter represents the you are which is bound to a particular
function.
So FPP not route whichever you are you want if at all, for the root function.
You, you want to pass certain parameters.
Those parameters can be given as the options.
So this is the syntax of the rule decorator's.
After the rules are defined by the rules decorator, you have to run the application by calling the
meter.
So Eppy not run.
It takes four parameters are for arguments, one is the host.
The host on which your application will listen for the requests, the default is the local news.
You can also identify the local lost by 127 one zero point zero one is the IP address of the local host.
If you want this development server to be available from the external IP, then you can set it to zero
zero zero.
Board, no, we know that the Web server is bound to hostname and port names the default, what number
is five thousand?
You can change if you want.
Debug option can be, you know, enabled or disabled depending on the requirement.
What is the purpose of the debug option?
I will tell you just afterwards and any other options that may be required to be passed to this Web
server.
So these are the four option four parameters that are required to this.
So this is a sample code of a simple hello flask application, as I said in the beginning, to import
the flask from the last module from flask, import, flask, OK, then create or declare an object applicable
to flask takes one argument the name of the module in which it is named.
Now this is the definition of the rule.
I'm giving a slash at Eppy dot route.
Not to this.
You are in this function is mapped.
What is the name of the function?
I know what this is called a review function.
When this you are it is given this function will be executed.
And in turn what, what it will do, it will return this string.
Hello.
That will be rendered on your browser.
This is of course the syntax or mechanism that you generally use to execute the module as the mean.
Now when this Python script is executed, when you run this script by saying Python, hello, why?
If this this script is named as PUA by Tom Hello Rajput, what happens?
The server will start the WGI server development server will start and it will tell you in the python
shell that it is running on STP.
This localhost, the server starts running so the program is run.
These are already started, started running.
All you have to do now is to go to the browser.
In that bar you either you can give one twenty zero zero one current five thousand or you can you localhost
firefighters one and see what happens as soon as this.
You are really given this one, this HelloWallet function will be executed.
It will return.
Hello.
World as a string and it will be rendered on your browser.
So that is the simplest way of generating or displaying world on your browsers page through the application.
Now, you found that there is a debug option to the running method.
Usually what happens when you are in a process of developing an application, you frequently want to
make certain changes into it.
So every time and are certain modifications or changes done, you may have to stop the server or when
the program listing make the corrections and again run it.
So this is a slightly tedious process.
So you can avoid that by setting the deeper option to do so.
If you step debugging, you want to prove no need to stop the program, stop the server chip, make
the changes, save it and run it every time.
You don't have to do this in each other, even if the server is running.
You can go back to your code, make certain changes, save it.
The server will automatically sense that a certain change has been done and it will automatically reload
the contents of your backend program.
So that is the benefit of setting the table is equal to as can be used when is set up or debug ep the
name of the object that you want to prove and then run.
Or you can use this debugging you want to do inside the Blackwaters.
So what ways you can do it?
The benefit of it is that while developing you don't have to face the hassles of stopping and starting
like this.
Lastly, when you say that when you run the program.
In the development environment, the development environment is available only on the local machine
on which the environment has been set up.
Because the development support has been enabled, so when their support has been enabled, the support
is available only on the local machine.
If you want to make this application available to the external IP address, then what you have to do,
you are to set another parameter hostage equal if you say is equal to zero zero zero zero, and if your
computer is having a, you know, connection with the outside world.
If it is having a static IP sort of thing, then this application, the application that you have written,
may be available or will be available to the externally external environment so that your server will
become an externally visible server.
So these activities now, I will practically demonstrate in front of you so that you will be able to
find out how exactly to write a hello world application so far.
We have successfully installed flask.
In our virtual environment now, we shall write a simple hello world application using Flast, so first
line is required to import the flask module into our application.
Next is to create a flask object.
Which takes the constructor of the flask plastic's one argument, which is the name of the current module
and that is retrieved by that will underscore the name of the school.
Then you are to use the rope.
Method of the flask object.
What Israel is doing is route is called the corridor, which tells the flask server, which is the.
You know, function, which is associated with this, you are.
So which means that this forward slash you want in front of the record, in the room means that this
forward slash is attached to this function.
So if I invoke the server and you.
This forward slash in front of the name of the server.
Then this function will be executed.
So.
When this.
Script will be run, the AP did maybe not run, run function, then Metalious available to this flask
object that will be executed and accordingly, whichever path that you mention in the you are in the
associated function will be called.
So what I am going to do is I run this application from the python, from the Python prompt will show
me that the server is running and then we will open the browser to see the world message that is being
printed.
So this was.
The script of the Hello World application.
Now, Norwegian.
Start the application, our virtual environment is in the flask in redirect.
So first we have to activate it by seeing.
Activity, which is in the scripts folder of the class in the Virtual Environment Directorate.
So it will be activated.
Then we are to run the script out by.
So if I press enter, what will happen?
The message will be they're telling me that the server is running on.
One twenty seven point zero one zero zero one zero point one.
That is the address of the localhost, the default for these five thousand, so on this, the server
is running.
So if I.
Go to the browser, give this URL, I should be able to see the hello world message being printed.
So let us open the browser and give the Yoran, as you know, being displayed there.
Now we shall see how the debugged support can be enabled in the flask application.
Actually, our application is right now running.
At the U.N., you are so I will first stop it by control.
And then.
Inability work, supervising the work equal to two.
And ran the application.
You see, there are certain changes in the output that is being displayed.
It says that the weather is active and it is the application is running on the same.
You are.
OK, so if you again go back to this localhost Quillen 5000, and it will again show you the whole.
So the hello world is displayed now, what is the effect of this debuggers equal to?
If the devil is not set equal to two.
And if the application is running after the app while the application is running, if you make any changes
to the Python script.
Then for every change that you may have, you may want to make to this fight on application, you know,
to stop this or make the changes, restart the server and then.
Open the browser now that they're debug is through the work, support is enabled.
What you can do while the server is running itself.
You can do whatever changes you want.
Those changes will be automatically refreshed without you having to stop and restart the server.
That is the advantage of Diebel.
Our application is already running in the world more than the work is set equal to do you know what
I will do?
I will make certain changes here.
Something like this.
And save this.
As soon as I see you, you see that.
That is saying detect change in the script, and it is reassuring it.
So this is what happens when you.
And they will debate more now if I go back to the browser and just refresh it, I should be able to
see the Halo tutorial point instead of Hellewell.
You do not have to stop this or make the changes and then again relaunch it.
So it has already reloaded the script.
And just refresh this.
That is why the changes have been automatically incorporated.
So this is how the debug effect, neocortical through, affects the behavior of the.
Server.