Deploy a Django app on Render for free | It covers Docker and staticfiles

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up guys today we going to talk about uh deploying a Jango application on render render it's a cloud provider you can deploy your web applications you can have a fully managed poql database uh you can host your static sites background workers current jobs and many more right uh today I'm going to talk about uh deploying a jungo application on render and if you've not signed make sure you sign up they have a free tier account so you can uh deploy web applications maybe to Showcase it to your recruiters something like that and uh yeah you'll get to connect your GitHub account you'll have to connect your GitHub account cuz you'll be getting the code from GitHub so that you can deploy it on render uh let's get started hello guys so this is my code right here I'll just run the server so that you can see what you're trying to deploy here okay let's start the virtual environment okay it's a straightforward application it's nothing much as you can see it's just an image and um there a CSS file that I'm using to apply the style here and uh a text right let's go back to the code that's what we going to deploy so it's nothing much so let's start with the doco file right uh for the doco file I'll just copy this a just uh file here I'll just copy it and paste but you're going to go through each line okay and just P right here so we starting by setting up our Docker file and for the doer file as you can see here we just uh bringing in the B image uh setting up the work directories up then setting these two environment variables here they are crucial if for python application that is uh then we updating the system dependencies and uh we now installing our dependencies for application what's inside here the requirements the txt file then yeah we copy all the directories inside this working directory that we've set up here then yeah then we use J Unicon uh to to run the to run the server we don't use the Run server run server is for run service for during development okay so I want to talk about talk a bit about um serving static files in jungo when you use R server you'll know that it always serve the static files it always our web application will serve the static files right but when you use G Unicon your application does not have the static files now when you use G Unicon you'll have to use an external service like um like Amazon is three bucket or maybe you should use uh engine X right those are the options that I know but there's multiple other options so for this tutorial I'm going to use white noise so what white nose does White Noise will it's a python package it's a python package it will enable us to our python application to serve its own static files to enable a python application to serve its own static files we won't need to have to use uh X or Amazon S3 buckets right so let's go to the White Noise documentation this is the White Noise documentation we're going to install it then we set up we set it up right it's nothing much people install white noise so I'll just drop the server be install White Noise all right as that is installing there's some stuff we have to set here like the the middleware we have to bring this white noise middleware again you can see it is just below the security middleware in middleware all matters in Jungle middleware so we need to bring it beneath security middleware all right where is it right here bring it there then um what's next this is the last setting we need to set uh static files storage just bring it down here uh okay just bring it there yeah just like that white noise is set up so when I run G Unicon uh when I run G Unicon code wisg this Command right here my static files they'll be served right the our python application will serve the static files and one more thing I need to set is the static route so static root is just uh the directory where all our stat static files will be collected all the static files in application they'll be put in one directory just name static files yeah uhhuh then I like to talk about also I've set up some environment variables here I just set it up so that you can also set it up on on render so that you can know how you can set an envirment variable on render so I've just uh bringing just to environment variable secret can debug but of course there's many more variable database configurations email configuration there's a lot more but for this tutoral I'm just going to talk about these two environment variables and also I want to set up allowed host for allowed host I just set up um cuz we're going to deplay on render the domain is going to be on r.com right so let me just set up on just put it as on renter.com so it will be any other words before this dot.on r.com will be our allowed host they can uh send request to this application here yeah so um I think that's set up right White Noise G Unicon Docker file yeah and for this Docker file you can find it on my gist I'll put the link in the description and also guys be sure to subscribe I'm going to upload another video using S2 buckets or inex just put it in the comment section whatever you want I'll do it then um yeah man so what I'm going to doing right now is I'm going to push this codee to GitHub then uh remember our render we connected it with GitHub so they'll find the render will get the code from GitHub so we have to push this code to GitHub right um so I'm going to do it do the do the same on your side then yeah let's meet on the other side so guys one thing I forgot is um you should also update your requirements.txt files I did not update that I installed uh G unicor and and render and uh sorry and white noise but not update my uh requirements.txt file so make sure you do that to update your requirements.txt file just do uh pip freeze and uh I think that okay I did not install G Unicon also install gunic I'm sorry for this guys also make sure to install G Unicon okay then update it again all right let's meet on render okay guys uh we are on render right now make sure you're on your dashboard right on this tab right here dashboard then click on the new button right there then you want to deploy a web service click that then connect a repository the repository that you just pushed connect it just like that then uh give it a name I'll just say jungle deploy render or deploy jungle render Jung on render I'll just leave the region is that Branch main yeah for the ROM make sure it's Docker it will automatically detect render will automatically detect your Docker file so it will say the run time is Docker don't select Pyon 3 select Docker then ahuh for the you will head over to the advanced section be sure to add environment variable remember we we had set up secret key so secret key and for the secret key let me show you how you can generate a secret key as sub let first I just import Secrets I know you know this but you know let's just do it all right right there you get a secret key then you can paste it right there okay paste and uh we also set up debug the debug you since you uh you're deploying application so be sure to set it as false then that's it I think that's it yeah then create web service let's just wait for the magic to happen it's a pass platform so there's nothing much you just have to bring in your application and it will do all the rest it will set up the run time by itself it will take of the of the infrastructure and all that you know it's very easy to deploy on render so what you're now waiting just waiting for it to build as you can see it is installing the dependencies now here what is happening it's running what's inside our Docker file right it's installing all the dependencies and uh yeah man running all those instructions that we put on a Docker file then it it will spin up a container so let's just wait uh yeah guys on my side it's you can read it's saying uh your service is live uh if you if you on your side is there's an error make sure you put it on the comment section I'll check it 100% and I'll help you out yeah man it's working guys it's a success it's deployed successfully all our static files have been uh our python our python application is serving them right you're not using Amazon S3 or in X but if you want me to make another video using Amazon S3 and or in X be sure to subscribe and tell me in the comment section right so guys it's a success be sure to subscribe have a good day man all right ciao
Info
Channel: CodeWithRay
Views: 3,388
Rating: undefined out of 5
Keywords:
Id: P7UsteRXt_o
Channel Id: undefined
Length: 10min 56sec (656 seconds)
Published: Sat Aug 26 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.