Hi, welcome to a new lecture on how to
deploy your flask web app on a live
server, which means that you're going to
have your own domain name, which you can
give to anyone, and they can use your
web app, and we're going to use PythonAnywhere.
So go to pythonanywhere.com.
PythonAnywhere has a free
service, where you can host your flask
applications. So this is what we're
going to do, and it's relatively easy to
deploy on PythonAnywhere, so this
is an updated video, actually, of the course.
Before of this, we used Heroku. Now,
Heroku and PythonAnywhere both allow
you to host, to deploy flask applications
for free. The difference is that PythonAnywhere
tends to be more user friendly.
And Heroku, on the other hand, makes it
harder, and so I usually suggest that as
a programmer, you want to focus on your
codes, instead of dealing with server
administration issues. Although I would
also like to say that both Heroku and
PythonAnywhere are relatively easy
compared to if you had your own server
where you have to handle
everything. So still Heroku and PythonAnywhere
makes things easier. To be able
to deploy your flask web app on PythonAnywhere,
you need to sign up for an
account, so go to Pricing & sign up,
and you want to find the section where
you can create a beginner account
because that is free, and they also have
other plans paid, so if you have more
visitors, then you'd have to upgrade to
a paid account. So I'm going to create a
new account. All right, so I signed
up, and my username is
ardit12345. That's my username, and this is
the dashboard. Now on PythonAnywhere,
besides deploying web apps, you can also
do some other things. So before we
deploy the web app, let me give you a
short tour on PythonAnywhere.
Basically, you should be able to see the
dashboard menu here, and then we have
Consoles. In Consoles, if you go to
Consoles, basically you can create a
Bash console,
[No audio]
and that gives you access
to your own server where you'll deploy
your web app, and you could also do
other things such as you can start
python3, and it starts that version
of Python. So it's an interactive python shell.
[No audio]
You can even import some
libraries here. So pandas is already
installed, you can use it. The downsides
of this is that you don't have a
Graphical User Interface. So if you want
to show to generate some graphs, and you
want to see them that's not possible on
PythonAnywhere, because all you have is
this shell. So the python shell and you
go back to the terminal, and for example
with pwd, you can see where you are
currently. So that's your location in
the server. So you are inside home, and
then inside ardit12345, so that
folder of the home folder. Here you can
also create Python files, for example,
nano example.py. So nano is a text
editor, which you can use in this kind
of command line interfaces. So that will
create a new file, and here you can
write Python code such as print
Hello,
parenthesis. Now, to save this
file, what you want to do is you want to
follow these commands. So exit, you want
to exit with Ctrl X. So press Ctrl X,
you'll see this message. It says Save
modified buffer, which means do you want
to save this file? Y for Yes or N for
No. So I'm going to press Y and then it
asks you again what name do you want to
put to your file example.py as it is
Yes. So just press Enter now, Enter and
the file is saved. To run it, you do
python3.9 example.py run and you
get the output. So that's what you can
do with the Console if you go back then
you have this files, and here now you
can see that example.py which we
created previously is here, and you see
the current directory, so home/ardit12345.
That's the directory, we were in
the command line interface. So this is
another way to create files. So if you
want to create a file here, you give a
name in here, let's say example2.py
and go to New File,
[No audio]
and let's say here I am print Hello Again, and
now you can also run this file, save it
and run it from here. So Save it first,
and go to the Run button, and you should
see the output down here.
[No audio]
This is a bit slower than the previous
way to run application, to run Python
files. But anyway, this is the output.
So that's another way to run Python
files. You want to go back now, you can press in here.
[No audio]
So this is a Files page
and then we have Web. Here is where
we will create a new web app, but in the
next lecture, and then we have Tasks.
With Tasks, what you could do is you
could enter here, the path of one of
your PythonAnywhere Python files. For
example, if you, if I wanted to give the
path of example.py, I would say
home.ardit12345, the
directory, and example.py, and then I
would define a time, I would set a time here
in UTC system, time system, and this
script then would be executed at that
time every day. This could be useful for
things like web scraping, if you want to
scrape something at a certain time every
day. So you can do that on PythonAnywhere
as well, and lastly, we have a
Databases menu. Here is where you can
create a database. So if your web app
has a database where it saves the data,
you want to create a new database here,
and then create a table for that
database. Again, it's, you can do that in
this interface here in databases, and
then your web app will be able to
interact with this database. So this was
an introduction to PythonAnywhere. In
the next video, we're going to deploy
our Python app, so our Flask app on
PythonAnywhere, see you.