Hi, welcome back. I'm excited to show you now
how to deploy your web app on PythonAnywhere.
So this is my PythonAnywhere
account, and I am in the Dashboard
section currently, you want to go to Web.
[No audio]
And there you want to create a new
web app, and you get this message here,
so PythonAnywhere is letting you know
that you cannot have a custom domain
name, let's say, ardit.com. Because
this is a free account. If you want a
custom domain name, then you want to pay
to get one of the pre-paid accounts.
First, though, you want to find a domain
provider to buy a domain name. So if you
want to buy the domain name example.com,
for example, you would want to go to
maybe Namecheap, Namecheap is I think
the best one to get domain names. So
namecheap.com, and once you buy a
domain name there, then you, Namecheap
will give you some DNS names, and those
names you have to put here in a PythonAnywhere
to connect them to your web
app. However, we're not doing that now.
For our purpose, it is enough to have
this kind of domain name, which is
in my case, this one in here.
So ardit12345.pythonanywhere.com.
So this is a subdomain of pythonanywhere.com,
press on Next, and you
have several options, the one we want is
Flask. So you can deploy different types
of web apps on PythonAnywhere. We press
on Flask and Python 3.9 is good to go.
So press on there, and this is now the
entry point of the Flask app. By entry
point, I mean the file that you
run to start the Flask app. So in
our case, it is script1.py.
That's the file that we run with python
script1.py. So don't change that,
just leave it as it is. So press Next for now.
[No audio]
And the app is created. But we
need to add our files to our app. So for
that, you want to go to the Files menu,
and now, here on the left, you can see
mysite, if you click there, you're
going to see the file that PythonAnywhere
created. So this is a entry
point that I was talking about,
flask_app.py, you want to
click there, and you want to delete that
code and paste, copy your own code and
paste your code in there, and press on Save.
[No audio]
So you can see now that we are in
this directory, so /home/ardit12345
so your username, mysite/flask_app.py is our
file. So if you click on mysite, you go
back to the root directory of your
project. So that's the root directory of
PythonAnywhere and this is the root
directory of our local project. So
script1.py is there and then it
has a static and a template folder in
the same root directory. Therefore, in
this mysite root directory, we want to
create a templates folder, so write
templates there and press on New directory.
[No audio]
That will create a new
templates folder. You see now it changed
to this folder. So if you go back to mysite,
you see templates is added in
the directories, flask_app is
also in the same folder mysite, and we
also want to create a static folder
empty, New directory press on that button,
and it should create a static folder. So
go back to mysite, you see static and
templates are there now. So we need to
add our static files, so press on static,
you are on static, inside static now, and you
want to upload
[No audio]
main.css but wait
this is in another folder, css is the
folder. So you want to create inside
static, you want to create a css
directory, press on New directory. Make
sure you are in that directory,
so mysite/static/css and here now
we want to upload a file and that file
is this main.css. So here I am. This
is the project directory with our local
files, under static, under css, we have
main.css, double click, and it will
upload inside css, then go back to mysite,
go to templates, and upload the
files that are inside templates, which is about,
[No audio]
home.html, and the
third one layout.html, these three
are inside templates. So make sure they
are inside the templates, then go back to mysite
and just have a look, if everything
looks good, it looks good to me. One
change you want to make also is that you
want to go to your app, and when your
app is in production, you
want to change this to false. So you
don't want to show visitors Python
errors, because that could make your
app prone to hacking, because people or
hackers will see here the errors of your app
and they may understand how your web app
is structure, and you may also expose
data which you don't want to expose in
those debug error messages that flask
shows. So False and press on Save, and
now we are ready to see our app. But
after we have reloaded the app with this
button, so under Web, the Web section,
press on Reload that button to get the
latest version of the files served by
PythonAnywhere. And then you want to
click on that URL, so that's the URL of
my app, press there, and mysite is
online. So it's working just great.
[No audio]
I hope yours is working too. If not, then
you want to go back to the Web section
and scroll down and look, locate this
Error logs. If you press there, you're
going to see the latest errors that you
got from your web app. So these are
Python errors and try to read them to
understand what's going on. Thanks a lot,
I'll talk to you in the next videos.