How to Deploy Django App on Heroku with PostgreSQL Database

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what's up guys i'm back with another video this time i'm going to show you how you can deploy your django application on the heroku platform we got a follow around 10 steps to get there let me show you how the first thing you need is going to be your django application so you got to be ready with your application beforehand if you are then we will be installing some additional packages such as cycle g2 g-unicom django heroku and white noise those who are wondering why we need this cycle g2 it is because i'm going to use a postgres database later on uh so for that postgres database we need this little piece of package installed and what about unicorn actually hiroko needs a web server gator interface to run your django application on their platform without it uh hiroko is unable to run our python application makes sense so you gotta make sure that unicorn is installed properly then we also need our two more packages to install one of them is django hiroku which is uh which automatically configures your application to work on hiroku and finally white noise to collect your static files now let's move on to step number three which is nothing but writing a runtime.txt file it is a tiny bit of a file that barely has anything inside it it defines which version of python is going to run on the server i will show you that in a second then we need a profile which is also called process file this file is one of the most important files when you are dealing with the helicopter platform without this proc file we will fail to deploy our app so much needed file uh step number five is to generate a run uh requirements.txt file hiroko needs to read this file first and install the necessary packages on the server for us step six is to create a github repo and push our local application on that referral step number seven is to create an app on the hiroco platform if you already have an account on heroku platform you can create an app there easily free of cost don't worry about it it's not that scary i will guide you through how to do that step number eight is to add a database on heroku which is going to be postgres in our case number nine is to adjust postgres database credential on the settings.pi file and finally number 10 would be adjusting the settings.pi file one more time for static files collection now i have a plan okay uh let me uh tell you the plan here you're seeing the django application in the top left corner right uh this django application is needed to be post on your github repo and after logging into your heroku account we will kind of pull this shangri application from the github repo okay and finally hiroko will make sure that our application goes live successfully now if you can finish all of these steps alongside me you are guaranteed to succeed uh let me tell you one thing though please try to see the entire video and avoid skipping it is because you might miss one critical step and end up being unsuccessful so stick around and keep on watching now i will show you all of the steps sequentially before doing that i have one request guys please please please hit the like button and if you think that i should continue creating these sort of videos and tutorials then please please please subscribe to my channel it's not gonna cost you anything guys just hit the like button and consider subscribing this is gonna immensely inspire me to create more videos like this so please uh enough talking now let's jump onto the visual code and proceed further welcome back on the visual code um i have already created a django application which is named at ddh this is a sim very simple application uh but you get the idea that this application you're trying to deploy on heroku okay guys uh now i'm going to install uh four packages um as uh discussed earlier so those those are gonna be the psych of g2 unicorn jango hiroko and white noise so i'm going to write down over here and it will start installing so yeah it is installing uh four or four packages for us and let's be freeze it seems like uh we successfully installed all of them now we are going to create a runtime.txt file [Music] runtime.txt and oh i think i made a mistake it's not done time it's run time make sure the spell is correct so runtime.txt and this runtime.txt will define uh what the python version would be so what is your python version um i we need to check so python does this version and oops i think i made a mistake python version and i think it says python 3.7.4 right um but here's the thing i'm not going to say python 3.7.4 i'm going to say 3.7.9 rather it is because i have already tried with 7.4 and it did not work for me so i'm gonna use the higher version 3.7.9 which is computable with a recent hiroku platform i guess and there's another thing um it says the bigger p right it says the bigger p over here at the bottom but we are going to use the smaller case uh smaller p a smaller ksp i would say ah otherwise it won't work so let's save this one run time takes round time.txt is done now i can create the profile [Music] this profile will be having um some text inside and i'm gonna copy and from somewhere and i'll paste it here so that's the thing you gotta write uh python manage.pi dot migrate and web unicon and you gotta write your application name over here so in my case ddh uh you should be writing yours ah the proc file is saved now so profile is done ah then we can um generate requirements.txt file so let's write pip freeze requirements.txt okay so the requirements.txt file is written you can check it's done okay now we are okay with this requirements.txt i can go ahead and create the github repo um actually i already uh created a repo for this application it's called ddh so you've got to be creating yours once this is done um i think i need i need to push this on the repo but before doing that i can also go to the heroku platform and i can create an app i think we already discussed about that because we need to create an app before we can pull the repo from github to heroku so let's create an app new create new app [Music] it's it's gonna be let's say the ah app is available okay let's create that [Music] okay it seems like it is all right and now i can um create a database as well so let's say resources [Music] let's go to the resource and i think i can write postgres over here heroku postgres let's click on that [Music] let's submit order form and it will generate a heroku progress for us [Music] once this is done um we can go to this postgres database um i mean you just click on that thing click on that here google space and it will redirect to this page it says not okay it's there now so you will have multiple options over here let's go to the setting and let's go to the view credentials and here you can see the all the credentials we'll be needing so let me copy this hostname and let me go to this settings file [Music] where is the database one okay this database one i think i need to change this database credential uh so let me change this database credential i'm gonna comment out these and because that is for the postgre and that is for the sqlite but we need this for postgres so now i can go and copy this uh this hostname and i can put it over here not this one i think this one okay i think this one actually sorry about that the host okay and then i can go to uh check i can copy the database name and so that's the database name i can go and get the username and also the password okay hopefully it is done so let's save this one and i have to also do some adjust adjustment uh let me import this static route for the file collection so [Music] i'm going to have this let me comment out this i don't need this so this static root is for the um static file collection uh let's say you have some images and static files then you will be needing this um so you gotta write django heroku.settings.locals and you say the static root is slash static so you kinda write this down and it will be okay don't know about it and uh for this uh i have to import some stuff so let me import on the top [Music] so i'm importing os and django heroku and also i need to allow uh the host so so the allow host part i'm gonna write this instead so it says ddhiroco app.com so that's fine and yeah that's pretty much it um so now i can kind of push this so get status and it says get add let me commit this git comment um message this is the first push okay so that's gonna be committed and now get push upstream origin master okay i supposed right okay and i can also do some like python start by and i can say make migration and i can say python manage dot by migrate so that will migrate our database on postgres on heroku [Music] okay it is migrating meanwhile what we can do um we can kind of come over here and refresh this let me check if it is here yeah the push is here and now i can go to the i think i should be on the app so let's say overview now it should be on deploy so let's click on deploy and from deployment please uh check this github one so because we are collecting our application from github and uh so repo name is gonna be ddah so let's search and it gives you the it shows you the github repo name so that's in my case this monitor 090 is ddh and you can connect and it will now it's going to bring your application over here it's ready you know uh if you have multiple uh branches it will show here uh in my case it's just master so it is already selected and now all you have to do is just uh click on this deploy branch okay let's let me do that for you [Music] finger crossed let's see it is installing sqlite it is installing pip setup tools yeah seems like it is installing it's going to take a while uh maybe a couple of seconds um so meanwhile you can go and uh like my video and you can also hit the bell icon and subscribe my channel guys um yeah seems like it is working and what about these um [Music] postgres one um database one you can see it has created 48 rows out of 10 000 so that means um the migration is successful as well um so yeah it says release command declared ddo a0 app deployed to hiroco seems like it is working it will take a few seconds more i guess yeah and it says deploy to hiroku your app was successfully deployed so now you can click on that view button and it will open up your application yeah so that's gdh appearance you say you write admin and you can go to your admin panel so yeah that is pretty much it guys so thank you very much and i'll see you on next video bye bye
Info
Channel: Code Aura
Views: 17,141
Rating: undefined out of 5
Keywords: how to deploy django app, how to deploy django app on heroku, django heroku, django app heroku, django deploy, deploy django heroku, heroku postgres, django postgres, deploy django, django postgres on heroku, django rest framework, django heroku github, how to deploy django app from github to heroku, github heroku, deploy django from github to heroku
Id: 5d8AQFF0Ot0
Channel Id: undefined
Length: 14min 38sec (878 seconds)
Published: Sun Jun 20 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.