How to Deploy a Django App with Postgres on Vercel | Coding for Innovations

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so hello guys so in this tutorial we're gonna have a look on how to deploy Django project on yourself with the possess TV so let's get right into it so at first we'll just create a virtual environment I am going to use my first python version as 3.9 so it's so I'll just create a virtual environment and activate it search then slash activate so my virtual environment is activated so I've activated in the current directory so now I'll install Django the prince card Django like I'm gonna install Django version 3.2 which is the LDS version so greater than or equal to 3.2 meaning it will install Voice is greater than 3.2 but less than 3.3 so in my case it's going to install Django version 3.2.60 so I hit the freeze yeah I get Django version so and now I'll create a Django project you can go admin I create a start project as I can period period indicates that it will create in the same directory so it's back end and here's the settings.pi so let's just run it so python manage that by run server so yeah so it's actually working and then now if I go to my admin panel it's going to load the static files so now what I'll do is I'll just create a simple view new file views dot file uh from shortcuts import render Define index yeah I'll just render an index context maybe something else title hello world yeah and now over here I'll just create a template slash index.html so it will be a H1 tag hello and then what did I call it over here so that will be title then let's put an exclamation mark yeah so I've saved it all the files and now let's go to my urls from dot views import index so path index and now my web server is running and now we'll go okay so I should set up the templates so I forgot about that my bad baster slash templates and now we should render yeah so it's rendering so as of now everything is done uh this is what we're gonna deploy but we are going to use a postgrades DB so as I said so flip install the wait I don't know the package name so postgres python and yeah yeah it's this website Maybe yeah I got it it's this but we are going to install this but we're gonna install the binary version of it which is just a C plus plus drivers which is included with it yeah and now fifth install I'll even install DJ database URL yeah so DJ database URL is also defined so and now when it comes to deploying it to reversal you need to create a virtual.json so let's create a Json file I'll just give it a version which is you're going to use the version 2 of it starts and then comma the UI it's going to be built yeah so GitHub copilot is giving some nope I'm gonna use back and slash which is this the SRT is pointing towards the entry field of the Django J5 and we're gonna need these two USC use we are gonna use varsal slash python yeah this one is versus python and I'll keep it to 15 megabytes then we're gonna give a runtime runtime is going to be python 3.9 yeah so after that after after the config we are gonna give another SRC okay so not over here sorry we should give it away here come up SRC so srcs build that assets uh what you want from create another object and now it's another SRC so in this SRC it's going to be bill.sh this file we are going to create it in a moment and now we are going to use static files so it's going to be at reversal slash static build static hyphen vui LD static build and for that the config distributor is going to be static files the UI I'm gonna name it like this for easy convention yeah and now is going to be routes and yeah it's giving me the correct yeah so destination is back and Slash and now for the SRC now to serve the static files to serve your static files is going to be slash static slash dot star so and then I'll point it to I'll point it to slash static Flash it's going to be dollar one so boom our config is ready and now we need to create a build.sh file so from this build.sh file the virtual is going to start building our our project so let's start with hash dollar sign and it's gonna be slash pin slash bash to show that it is a starting and then building the project as with that and then I go building the project and now python 3.9 hyphen m m install Dash r requirements.phxt this is going to be the first like installing the project and now we are going to do is Let Me See Echo make make migration so it's gonna be by make migrate I'll just pass it a no input flag and now it's going to be python 3.9 8.5 I'm just going to give it a migrate with the same flag so the migrations are done and now it should collect static so collect static no input that's as c l e a r yeah so this is where our for Django project is getting built the requirements are txt we should now create it so let's go to the terminal and now okay freeze q u i r e m e n t s requirements are txt is where all our requirements are specified yeah everything is done so and now we need to configure our settings.pi so that we get the proper we get the proper database to be used when we are deploying so now let's go to settings and now import OS and now import uh DJ database URL um okay I don't know why so let's run our program python manage that parent server do I get any error no I'm not getting any error so I don't know what's wrong so let's go to the database section database section so under this databases of default is equal to connection method SLS is equal to true I think you don't have to pass in any of these requirements yeah so in so let's create another dot Envy file and then we need to pass in the database URL so for that we are going to use for that we are going to use railways where they provide a free sqlite database I did not even log in but still they are giving C I do not even log in over here but still they are giving a free database so I'll just copy the URL so it's going to be database slash URL I'll give it a string and install keep keep this as of now yeah and now we need to install python decouple five so click to install python icon DC or up python decouple so the with this we are going to use the environment variables so I think there is actually nothing required yeah so I'll just leave all these two or maybe from maybe from the couple see you again for concrete okay yeah so it's okay and now we're gonna again flip since we since we updated our requirements or t85 yeah so this is actually pretty nice so we installed I copy binary DJ database URL so everything is so now only thing is elliptos on creating the static yeah and settings the static URL so now static Road is basically class [Music] SOC static f i l e s underscore the UI ELD build and then again it's gonna be static yeah so this is how you should name it so that it kind of can use the correct place so and now clear LS so and now we are going to like get status so get Inlet yeah initialize the database or initialize the git so now that is to get ignore yeah so it's gonna be star dot e and B and then bin lib and then I'll just save it for now and let's even do star dot SQ lite3 and then yep pretty much nothing else everything we need let's again run our server so clear let's get status you have everything so get it so now let now let me deploy it to GitHub and then let's get it hello guys so I have deployed it to I have deployed it to the GitHub and I have just made a comment right now so let's start building it so let's import this and configuration and then build an output everything is overdone so the environment variable is so let's go to uh dot EnV then it's going to be easier database URL and then and then I'll just pass in the string for virtual and then I'm gonna add and then I'm gonna hit deploy so now let me hit the deploy button okay so it should not contain hyphen ourselves so let's hit the deploy button yeah it is installing and okay it made all the migrations it started so let's see I've kept the debug at all no because it's a simple tutorial to show how to use both Django and so static price returns so let's assigning the domains assigned it's actually deployed let's wait let's check it out okay that's our last function has crashed yeah I don't know why so it's a good thing no problem so let's continue to dashboard and then let's view function log 3 idiotics yeah using Handler or file in okay so this is a very interesting thing so in our wsj file so yeah we named it as application so you want virtual expects you is to have it as app so if you have it as application it will draw an error so get yes so get as let's go to our GitHub repo and hit refresh see the details yeah so now let's check it again run everything collecting the static it's it's building it up so let's wait till what's gonna happen color this time maybe it will run it perfectly let's see and wait [Music] as completed assigning domains now yeah so our Django app is perfectly ready voila it's actually this is just a simple error not a big thing so let's fix this also um so and now let's go to allowance for safety purposes is not recommended we give it as true and now hit status with commit updated allowed course in the things start to find get push origin main so let it push it and now again let's let's go back to the GitHub and now let's refresh it again it is building so let's open it in the new tab yeah so let it build it so now now take very less time to build so let's see what's gonna happen now this should show the hello world over here that's what I'm thinking wait yeah I think it's actually done boom our app works hello world so and now I'll give it short with admin even a static pressure serving through jungle so this is a basic tutorial where you have learned how to use Django and deploy it on vessel so the source code is negative you can check it out and
Info
Channel: Coding for Innovations
Views: 10,031
Rating: undefined out of 5
Keywords: django, python3, vercel, postgres, deployment
Id: Ri-pFKtMX48
Channel Id: undefined
Length: 22min 54sec (1374 seconds)
Published: Sun Oct 30 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.