Deploy Your Custom Django Website on PythonAnywhere

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone this is my hell and today I'll be showing you how to take a jingle websites you have already developed locally and deploy it on Python anywhere first things first I want to highlight that I'm going to be using Python version 3.6 with the Django version 2.0 I also want to explain why I did this video I started learning Django by reading a book called Python crash course which is one of the best introductions to Python the burg described how to build a fairly basic block site in Django and deploy it in Heroku I went through the process pretty quickly even though I didn't quite understand a few the things I was doing for deployment nevertheless I was filled with confidence and I went on to develop my own custom websites a recommendation platform for mobile phones which obviously turned out to be a lot more intricate I then follow the same steps to deploy the site in Heroku but they didn't work at this time I searched for solutions on Heroku documentation Google Stack Overflow reddit but I still couldn't make you work I'm thinking am I being caused by the fact I haven't build the website the right way maybe I didn't pull up the right file structure or there was something weird with me one of my settings files either way I started looking for alternative hosting providers which were suitable for beginners the only one where I managed to get my website to work was Python anyway but it still took me a while because there wasn't a single video that explained the deployment process from start to finish so that's the story behind this video it's time to show you how I did it I'm actually going to start off by making some preparations locally the first thing I'm going to do is open up a command line I need to change the directory to the folder that contains my website this is the folder so I will copy the location and in here I'll type in CD and control paste for the location I then need to activate the virtual environment that was already set up locally I will then run this command pip freeze greater than sign requirements underscore personal text if I go back to the folder that holds all the code for my website you will see that a requirements and the score personal text file has been created opening this file up you will see that it includes all of the Python packages I have installed in order to run my website locally notice how even Django is here amongst many others later on I'll use this file to install all other packages on my hosting space with only one command we can now close both the text file and the command line the other thing I'm going to do is place the folder that holds my Jenga website into a single zip file while this is running I'll show you the dashboard you will see on Python anywhere once you create an account I'm using a free account which allows me to publish only one website without the ability to choose a custom domain the size processing speed is also slower compared to the paid version but that will not so much at the beginning the first thing I'm going to do here is upload my website's files once this folder here has been compressed I'll click on the files tab and in here I've got this upload a file button which I will click right now and I will wait until the folder finishes compressing all right so now that the file has been completed these it though that is I will just select it click on open oops just make sure that I have to select it click on open and wait for it to be uploaded there you go now you can see it uploaded here on my server space alright now I'm going to open the consoles page and click on the bash link which will start a bash console in the browser which is directly linked to my server space I will now run the following commands m'kay virtue Envy Gengo - o - - python equals four slash USR 4/10 or slash python 3.6 this command basically tells the console to create a virtual environment on my Python anywhere server space using python 3.6 which should be stored in the django to a folder alright once this has loaded up you will see that Django tool appears in brackets on the left hand side of the command line this indicates that will now be running commands in the virtual environment we created the next thing I'm going to do is unzip the file I uploaded on the server first of all I will check whether the file is in my active directory by typing in there there it is ok and now I will type unzip P recommend that's it to decompress the file while this is running I'll switch to another tab that has the Python anywhere website open and go to the web section of the sites I can create a website here by clicking on the add a new web app button I'll click this someone next click on manual configuration because we'll be using the virtual environment we set up using the bash console and python 3.6 great so I'll click on the reload button here to make sure that my website has been loaded up and if I open the link in a new tab you'll see that a generic website or web page really has been created all right I will then scroll down to the virtual envy section where I type in the name of the folder that holds my virtual environment that is Django tool and click on accept this sells a website to use the virtual environment I created on my server space okay I'll go back to the batch console I have open in my browser and hopefully the unzipping should be completed I'm now going to use the text bar I created at the beginning of this video let me first check where I am by typing in der and then change directory to the procurement folder that's again for see what files are in the procurement folder and you can see now the requirements and the score personal text file in my active directory if I then run the following command hit install - our requirements underscore personal text it will start installing all of the Python packages that I had on my local server including Django using the requirements and the score personal text file I'll switch back to the web page on Python anywhere why this is running and I'll open up the WSGI configuration file and then this fall here I will delete all the settings which are not relevant to my Django 2.0 websites the hello world section up until Django won't be of any use anymore so deleted just as a side the hello world section contains what was being showed in that generic website web page when I started my web app I will now uncomment all of the commands starting from this section here up until this section where it starts saying all four older Django 1.4 so i will uncomment import OS import sis path if path sister path o s dot environ from django and application the only other thing we have below is settings for flaws which I can which means that I can delete everything starting from Django 1.4 doesn't it feel good when you delete large box of code maybe I'm just being crazy anyway what we also need to do is make sure that these two variables here path and OS environs point to the right locations let's first have a look at the folder structure of our websites if I open a new tab and I go into fouls and then I go into he recommend which holds all of my website's files you'll see how it's being split up okay so what this means is that in the past I need to put in the name of the folder that holds my website's files in this case it's P recommend and that's what I'm gonna type in here the OS dot environment on the other hand needs to be linked to the folder that holds the project settings and my case the name of the folder is reco projects you can see here for example my settings are pipe out so it is the name of this folder that I will type in here instead of my sight all right we're now done with this file we'll save our changes and now actually go to our settings dot PI file the only thing I'm going to change here is the value of the allowed hosts variable which should be the star cards are between two apostrophes this basically allows our website's files to be accessed by any hosting provider including Python anywhere I'm not going to be making any more changes to the file but let's go to the bottom so I can show you something this section here contains code that I have added when developing my website locally if you haven't defined your static root path already make sure you do that now because this is the path where all of your files like JavaScript or CSS will be collected when we run the static files command in a moment you can use what I have here which is the path to a static files folder within the base directory now if you wondering where this base underscore dear variable comes from go scroll back up and you'll see it here defines as and you'll see that it points to the folder where we store all of our website's files you don't actually need to create the static files folder by the way it will be done automatically when we run this static files commands all right then enough talk about this command and let's actually use it I'll go back to you the bash console I have open and hopefully all of the Python packages should have been installed great so now what I will do is type in Python manage point collect static the command will read our instructions in settings dot hi and collect all of the static files in the static files folder if we go back into one of the pages that we had open on Python anywhere and make sure again that click on this save button and go into files and into the P recommend folder which holds my websites you'll now see the static files folder creates it here and indeed the site files folder contains static files like JavaScript or CSS inside I'll also make sure back in the settings file that I had saved this ball here and then I'll go to the web section where in turn I'll scroll down to the static files subsection there you go what I'll first do is type in static between two four slashes in the URL column then I'll copy the directory of the static files folder from the files page you have open into the directory column so I'll copy this path here and paste it in the directory the purpose of this is to help Python anywhere serve your static files faster on your website okay I will hit the reload button one last time wait for everything to load up and if I open the link again I should now see the website I have created locally initially now running on the Python anywhere host there you have it so that's it folks let me know in the comment box what do you think of this video or if you have suggestions for any other videos and see you next time
Info
Channel: Mihail Marian
Views: 35,756
Rating: undefined out of 5
Keywords: Python, Django, Deploy, Website, PythonAnywhere, Custom, Web development
Id: SCoGwHCNXVw
Channel Id: undefined
Length: 22min 50sec (1370 seconds)
Published: Thu Feb 08 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.