Deploy a Django web application to Python Anywhere [FREE]
Tutorial Hosting
Hi everyone and I hope you’re all doing great so welcome to my next video tutorial where I’ll be teaching you how to deploy your Django web app to python anywhere now I know some of you are
Probably wondering so let’s go over and click on pricing and sign up so if you see it here it does come with a free version here but just do bear in mind it is extremely limited but of course you
Will be able to at least deploy your application here and it will be live alright so just bear in mind that there are other pricing plans available some of them are a little bit expensive but just
Rest assured that there is a plan that is free and what you can go ahead and do is you can go ahead and create your beginner account all right so go ahead and create your beginner account and
Then we’ll move on to the next stage all right so make sure you go ahead and do just that so once you’ve created your beginner account you will then be able to actually log in with your account um actually what will happen is once you create the beginner account you’ll automatically be
Logged in once you complete the sign up process okay so make sure you do that create your account um remember to get there you just need to go to pricing and sign up here in the top right so yeah that’s maximized and according to this URL here so it’s at www.payerson anyway.com
And what I can also do is I’ll attach the link also in the description below so you can just click on that if that will be easier for you so go ahead click on pricing and sign up and just
Start by creating your beginner account first of all all right all right so by now you should have created an account on python anywhere and you should be able to access this location here that is your dashboard so usually you’ll be redirected to this location if not for some
Reason just have a look here at the navigation bar and look for dashboard click on it and it should be redirected to this location here all right so as we can see my username is honor96 so you will
Have your own username displayed here with a nice welcome message and you should see this page here something else that I want you to make sure make sure that you have a GitHub account and you are currently in the repository of the application that you actually want to deploy so what you can
See here is let me go to my actual um account so I am using my crowd with Django account and you can just head over to your repositories okay and I’m going to make use of my basic app here
Okay so this is the application that I’m going to make use of and you can see here that would be my URL so make sure you go into your project on GitHub accordingly all right so once you’ve
Done that what you want to do is scroll down and here on the bottom left you’ll see something that says new console what you want to do is you want to head over there and click on bash okay
And this will open a nice console for us okay so it’s just executing great now I know this is a bit small so I will zoom in a bit okay that should be okay it’s that let’s see what
That’s I’ll zoom in a bit more okay there we go okay that is that should be good for you guys all right so let’s get started so the first thing that we want to do is we want to head over
Okay and go to our home directory here so to do that okay we can say PWD okay and now we’re in our home directory so it shows home and then honor 96 so that will be your username
So make sure you are here next thing that we want to do is clone our project so I’m going to say get to clone and then go to GitHub with where my project exists copy that URL and paste
It in like so very simple press enter okay and it’s just going to clone our project accordingly now I don’t like to have all of these lines here it looks very unclean now a useful command that
You can use here in the bash console is to say clear and that will clear everything up so look a bit cleaner a lot better and so on so just be sure that you go ahead and do that
So in Python anywhere um we need to actually create a virtual environment so this is just how python anywhere works so to do that we can say MK that means make virtual EnV so basically we’re saying here make virtual EnV which means make virtual environment then space two
Dashes and then we’re going to include our python version so first of all we’re going to say python is equal to a forward slash user so a user in my case honor 96 and we want to go into the bin okay
And now we’re going to put in the python version so I’m running python 3.9 now a way to check what version you’re utilizing head over to your command prompt okay and you can just say python
Dash dash version okay and it’s in my case python 3.9.13 you don’t need to use the last extension just say the first two uh first two digits is fine so 3.9 3.8 3.7 that’s fine now I do want
To warn you here that you might have a problem here because I don’t think python anyway supports python 3.10 so you might have an issue with that so as long as you’re using python 3.9 and below
You won’t have any sort of problems or anything so I’m literally at the edge here because I’m on python 3.9.13 so just bear that in mind okay so apologies for that next thing that you want
To do is you just want to add a space and now you’re going to name your virtual environment so I’m going to call mine venv now make sure you remember what you call your virtual environment
Because we’re going to reference it later so if you want to if you want to write it down or anything I mean it’s only going to be like a few letters but just I want to place emphasis that you
Need to make sure that you remember your virtual environment okay and now you can press enter okay so it’s going to now create our virtual environment for us delicious wait for that okay there we go uh perfect and now we can see we’re in our
Virtual environment accordingly now I just want to clear this mess up there we go okay so let me explain this clearly here so if you happen to have a requirements.txt file okay we are currently in our home directory as of this moment so what you can do if you want to go ahead
And say pip install our requirements.txt okay you can head over to your project directory you can just CD over there and then run that pip install our requirements.txt so in my case my project is very simple here I mean I haven’t got anything crazy here going on
Um if I open my project here Elevate here we can see it’s it’s very simple there isn’t uh much going on all I really need to utilize is a Django so I’m just literally going to go ahead and say
Pip install Django now remember what I said what you’re going to need to do if you want to install your requirements.txt font you’re just going to have to CD to your your Project’s directory and then go ahead and install your requirements okay so in this case I’m just going to install a Django
Okay so let’s go ahead and do that okay so this should be relatively quick okay so what we can do what I’m going to do actually is wait for that to install so I’m going
To go ahead and pause the video and once that’s done we can move on to the next step all right all right perfect so we can see our Django Apple installed perfect so let’s clear this
Up all right so we’re going to have to open multiple tabs now so what we can do here is we can just duplicate this tab okay and what we can do is actually just go back here
And here we add the dashboard so we can zoom out here this is a bit crazy okay so what I’d recommend is you open a few tabs here so duplicate a few here because we’re going to be using
A lot of things okay so it won’t be difficult or confusing but we don’t want to have to open tab so just go ahead and open a few tabs on the dashboard because we always want to refer back here
So you’ll be glad to know that we’re now finally done with our bash console so you don’t need to worry about this anymore for now at least for now okay we will return to it but we’re done for now
Okay now the next thing that we want to do okay uh head over to your dashboard and you can see here it says open web tab because we have no web apps so let’s go ahead and say open the web tab
Okay okay so it says you have no web apps great okay let’s go ahead and create a new one so add a new web app okay so we can see here your web app’s domain name so for me
It’s going to be honor 96 so it’s going to be your username.payersonanywhere.com now you can go ahead and add a domain name so you go ahead and say upgrade now and go ahead and change that accordingly if you want um but remember it’s going to cost you money so if you just want
To keep it as is and you just want a uh your application Live okay free without any sort of um Hang-Ups or anything just go ahead and just say next okay okay next okay we need to select the python web framework and I know most of you are going to
Say Django now we’re not going to do it that way we’re going to do it manually so you’ll click on manual configuration and now you need to choose the python version now this is why I said earlier on in the beginning make sure that you have lower than python 3.10 because python
Anywhere as of this moment does not support it so in my case I’m literally right at the end so I’m going to choose python 3.9 okay uh great so we’re going to manually configure our wsgi configuration file this is actually very simple so not to worry now we can say next
Okay so let’s just wait for that so it does take a moment to configure and there we go so our web app is set up correctly as it should be okay so there we have it
All right this is great now what I think we should do we can close these links here and we want to just make a duplicate of this one here okay great because what we want to do in the end is the
Reason why I’m duplicating it is because I want us to connect to this URL in a moment not now because it’s not going to work so we can scroll down and scroll all the way down until you see virtual EnV
Okay so what we want to do here okay is we want to add in our virtual environment now if you remember early on in our case we call it venv so this is why I said you must make sure you write it
Down or remember it because we just want to add this in here so venv go ahead and add that in perfect so there is our virtual environment air location our path for python anywhere great now
What we can do now is we can go ahead and we can alter our wsgi configuration file so what you want to do is click on your wsgi configuration file it should be just above the virtual EnV
Section so under the code section here and just click on wsgi configuration file here okay just open that up okay here it is okay so what you basically want to do is you want to scroll down
Here all the way down until you see a Django now everything here in Django you don’t want to delete so everything from 89 to 74 to 89 just leave it everything else you can delete so if you want
Some clarity you can just watch what I do so I’m just going to take flask out here okay I’m Gonna Leave Django Uh custom wsgi you can take that out uh the virtual Envy this is just a comment
Okay this whole application here we can remove all the way to hello world so from line 13 hello world uh all the way to line 53 that says live okay you can go ahead and remove all of that okay and we
Can leave this up to here so we can scroll go back up here and make sure you have Django here okay so make sure you’re up to this point next thing that you want to do is you want to uncomment
Accordingly so watch exactly what I uncomment very important okay so I’m going to uncomment the application uh the from Django the OS part here okay our if statement okay that’s fine uh our pass sis and Os okay so everything here we need to make sure that we uncomment accordingly okay
So everything else is a comment as you can see here these are just comments and we don’t have if then so that is a comment as well so make sure you’ve got the following as I have so
Import uh OS import sys um pass if password says pass uh sysports.append I was done in viron from django.core wsgi import get wsgi and application okay so to summarize what’s going on here basically is we need to set the pass to our actual application so that’s effectively what we need to
Do next we need to set that pass accordingly all right so what we can do now is head over to the bash console so here unfortunately back again I just want to zoom in for you so make sure you
Head over to the bash console so what we want to do no I’m here so what we want to do now I just want to go back out of here so what we want to do now is we want to get the pass of our application
From The Bash console and copy it from bash and just edit it right here where you see the pass right here we just want to edit that out okay so head over to bash and let’s get started with the
Configuration right now the first thing that we need to do is we can type LS so Alice is going to go ahead and show us all the files in our current directory so here in our home directory we have
Basic apps so if you recall basic app is the name of my repository well my repository here basic app that’s the name of that let’s go ahead and CD into basic app in my case so in our application
Okay okay and type LS let’s see what we have Elevate so Elevate is my actual project here so Elevate if I click on that here this is my actual project okay so I’m in it right here
As you can see so I’m I went into I seeded into basic app which I did right here and now I’m cd-ing uh into basic app which I can see Elevate um right here at the end of this
Moment so if I type LS I should see elevate linksmanage.pi so if I exceeding to elevate now okay and type LS okay there we go we can now see manage.pi uh links and we can see all of
The following accordingly all right so make sure that you are here as of this moment so now we are actually in our projects directory Great so the next thing you want to do is type PWD
Okay and this is going to actually give us our projects directory here so in my case it’s in the home directory under my user honor 96 a basic app elevator so Elevate is my actual Project’s name so you can check that accordingly here so I have a fully here called basic app
And then my actual Django project itself here okay so I don’t want you guys to get confused so here we are and this is the pulse that we need so we can copy this pass here accordingly so let
Me copy that nicely so you can copy that you can press Ctrl C uh head over to this part here okay and here where you see the path we can just replace that like so and just remove those comments for a moment okay and we add them okay there we
Go so we just want to add a fresh pair of uh quotes sorry not comments quotes okay there we go so there is my app pass okay perfect all right so you want to go ahead and say save
Okay so this has been saved so our wsgi font has been configured appropriately okay and next thing that we want to do is we want to configure our domain name here so this is our domain name rno96.
Pythonanywhere.com go ahead and copy the domain name head over to uh we can head over to files okay so just get over there and what you can do is you can head over to your basic app here so this is my repository name basic app elevate
Okay and I’m going to go into my Elevate settings so I’m going to my settings.pi effectively and what I want to do here in allowed hosts okay I just want to put in the following here so my domain name okay just uh bear in mind you should actually turn the debug setting
To full so just a bit of a security tip there so make sure you of course change it to false but the main thing here is make sure your loud hosts is set accordingly here after you’ve edited
That go ahead and say save okay and what you can do is you can go out of this so you can go back so make sure you go back head over to your dashboard okay great now once you’ve done that you just want to head over to your configuration files here and
There’s one thing you want to say here and that is your settings here so depending on what you named your project in Django so in my case here I called my project Elevate here so this is where
My settings.pi exists so if I click on that okay this is where my settings.pi is and that is my project here so you want to set that accordingly here so I’m going to call mine here elevate like
So make sure you add that as follows make sure your pass is all set and go ahead and say save okay so that’s saved great now now that you’re on your dashboard here what you can do is you
Can go ahead to your web app here so go ahead and click on your web app here in the bottom right on all web apps okay and before you actually go ahead and connect to it you want to reload um your file here accordingly so go ahead and reload uh everything here
Okay so that just that does take some time okay there we go and now you can open up your application at this domain name so open that up and there we go so I had a very simple
Application but now we can see our application is now hosted um from python anywhere do bear in mind okay that this is free so you don’t need to worry about payments although it is very limited
In terms of the CPU they give you it’s very weak and very low but you know it is a way to you know deploy your application and like I said you can even go ahead and custom your domain name okay
So that’s it that is the basic way as to how to deploy your application get it running get it set and everything so this is an alternative way of deploying your Django replication to python anywhere for free so I hope to help you guys it’s very simple and relatively straightforward
So yeah that’s it guys and thank you as always for the support thanks so much till next time
Deploy a Django web application to Python Anywhere [FREE]
It took some time, but it's finally here. A free way to deploy your Django web application… @danimusbar Python Anywhere: https://www.pythonanywhere.com/ 💻 | Python Django: Build an eCommerce Store – 2022: https://www.udemy.com/course/python-django-build-an-e-commerce-store-2022/?referralCode=8C4D8A38D4BE143E4741 🧑💻 | All my courses: https://www.cloudwithdjango.com/courses ❤️ | My Patreon: https://www.patreon.com/cloudwithdjango 📑 | My tech blog: https://www.cloudwithdjango.com/ 🔶| GitHub: https://github.com/CloudWithDjango
#Deploy #Django #web #application #Python #FREE
https://i.ytimg.com/vi/xtnUwvjOThg/hqdefault.jpg