>> The first thing we need to do before we can
deploy is make sure that we have an account on Azure.
If you go to azure.com/free,
then you can register for the free account on Azure.
This will also give you access to free web apps.
Beyond the first 12 months,
you could actually run this app you've been working on,
on the free tier.
Once you've registered for Azure,
the next step is to go back into
VSCode and we're going to install some Azure extensions.
The Azure extensions of VSCode allow you to
deploy directly to Azure from VSCode.
First of all, go to the Extensions pane,
then search for Azure,
and the top item should be something called Azure Tools.
This is an extension pack that includes all of the things you
need to deploy and manage Azure from VSCode.
Install that extension pack and then once you're done,
you'll get this extra button on the left-hand side,
which is the Azure icon.
If you go through to that, it'll prompt
you to sign in for the first time.
Sign in with the account you just created on
the Azure portal or if you already have an account for Azure,
you can sign in using the existing account.
Then our next step is to go to the component called
the App Service and we're going to create
a new Web App for our deployment.
Click on this icon here,
"Create New Web App" and we
need to think of a globally unique name for the new web app.
This is unique across all web apps in Azure, not just yours.
I'm going to use ant-space-tours
as the name for my app and then press "Enter".
Then it's going to ask which runtime stack
you want so we want Python 3.8,
and then you can pick a pricing tier.
Like I mentioned, there's the free account that you've set up,
but there's also a free tier in
web app so even beyond the first 12 months,
this web app will be in the free tier so we can
pick free and then we're going to
get an update in the right hand side about all
of the steps as it creates our new web app.
Once that's completed deploying,
you should get this notification to say that
ant-space-tours has deployed and the URL.
If you want, you can click on the "Deploy" button,
but our app isn't actually ready to go into production
yet so we need to make a couple of changes before we can do that.
Remember this URL here,
so ant-space-tours.azurewebsites.net so we
need to keep that in mind.
We need to make a couple of changes to the app
before we go into production.
One extra thing we need to do before our first deployment
is add an extra application setting.
In the Azure panel go to
your app which is called ant-space-tours in my case,
and Application Settings then right-click
on this section to that Add New Setting.
The name of the setting is a bit long,
but I'll paste that in there as SCM_DO_BUILD_DURING_DEPLOYMENT.
This basically says that once you've deployed your application,
it's going to go and pull and install all the dependencies for
you so you don't have to log into the server and do that manually,
which would be a bit of a pain.
Hit "Enter" and then the value needs to be
one and once you've done that,
it will install all of the latest Django is what is white noise,
and do all that for you automatically.
Let's now go to the Folder View
and we're going to open up the Settings file.
Now towards the top you'll see
this big thing saying security warning,
don't run with debug turned on in production.
Now since we're about to deploy to production,
let's turn that off.
The DEBUG option is the thing that says,
if there's an error,
an exception or something,
it prints all that information for you in the browser.
That's great when developing locally,
but when you're running in production,
it means that anybody can see
that information and sometimes
that information can include things like passwords,
which obviously we don't want anyone to see.
Let's turn that off by setting that to false.
The second thing we have to do is
this setting here called ALLOWED_HOSTS.
We need to add the new domain name
that we're provisioning our website under.
Mine was ant-space-tours.azurewebsites.net so I can add that in
here and you'd fill
in whatever it is that you've completed for your application.
The next thing we need to think about is our static file.
When you're running that run server locally,
it's actually doing two things.
First, it's running the Django application,
and secondly, it's serving up any static files that you have.
These would include things like CSS and JavaScript.
To do that in production,
what we can actually use is
another package which makes things nice and simple for us.
If you go to requirements.txt and
then add a new dependency called WhiteNoise.
We're going to go back to our settings
file and configure WhiteNoise.
The first thing we do is go down to
the MIDDLEWARE section and we add
the WhiteNoise middleware,
which is whitenoise.middleware.WhiteNoiseMiddleware.
The link for that will be in the notes.
Next we go right down to the bottom of
this settings file to where we've declared
static files and the STATIC_URL to be /static. That's the default.
We need to add an extra couple of settings in here.
First we're going to say
static file storage should be
using the WhiteNoise package and then
secondly that we're going to have an extra folder that is
going to get created on the production server called Static Files.
You never need to worry about that folder,
it will get generated automatically.
These are just two extra settings that we
need so that when we deploy it in production,
it can find all the CSS files and JavaScript and things like that.
Those are the two changes we need to make
to our app before we can deploy into
production so let's go ahead and save
those changes and then go back into
the Azure pane and click on this button here to deploy to Web App.
It's now going to ask us which Web App we want to deploy to.
I've got quite a few actually,
but ant-space-tours is the one that we just
created and it's going to ask me if
I want to overwrite any previous deployment.
Since I haven't actually done a deployment
yet, that's absolutely fine.
But it will ask you that every
time so just click on "Deploy" button.
Then it's going to ask us, instead of asking
which Web App you want to deploy to,
shall we store a local configuration to say which one is default?
Click "Yes" and the next time you
do deploy with new changes or anything,
it's not going to ask you that question a second time.
It's going to take maybe a minute or two to deploy
your application and get that happen online.
If you want to see all the details,
you can click on this link here to see the logs as it's being
deployed and it'll tell you if there
are any errors or anything when it's deploying the package.
Of course once that's finished,
you should get this notification to say that your deployment has
finished and there's a button here
saying "Browse Websites" so go ahead and click on that.
There it is, your website has been
deployed on the Internet, so congratulations.
Give yourself a pat on the back,
you've written your first Django app,
and it's up and running online.
We can see here that our functionality is done,
we've got our tools,
we've got our navigation here,
we can look at destinations,
we can go back and see the Cruises.
That is looking fantastic so congratulations.
One last thing to note is that you might be
wondering what about the database?
We used a SQLite database when we set up this project so
this database that you've been working on
locally is the one that has been deployed to production.
If you make any changes locally,
the next time you deploy,
it will push those up into production.
However, if you make changes to the database in production,
maybe through a form or something,
and you deploy again, it will actually overwrite those changes.
That's because we're using
just a single simple file for our database.
For a bigger project,
really what you'll be looking to do is
actually set up a database server.
In Azure, we offer something called Postgres,
which is a widely used database server available.
It's an open-source project,
but we offer it as a service so you can actually
configure Postgres for Azure and connect your Django application.
We've got plenty of tutorials on how to do that.
But just to get you up and running with it,
nice and simple, let's stick with SQLite for the time being.