Skip to main content

Deploy Django app online for free!

So after a number of lines of code, brilliance and dreaming. Your next dream is for the world to see. Of course you can walk around with your computer and doing a 'manage.py runserver' But cumon guys, lets embrace the cloud.



Not like this guy though! I choose to deploy on PythonAnywhere. So you ask why?


1) Free amazing support - You actually talk to a live human !
2) Easy - Very easy
3) Affordable - As you scale up, it gets way better!


So by now I assume you are already on a version control system (So I will not waste much energy on that one). Maybe Ill someday write on my two favs Github and Bitbucket.


STEP 1:

Create an account on pythonanywhere. Kindly note that your username will be included in your apps url. So it will be like :

"yourUsername.pythonanywhere.com"


STEP 2:

Select other and set a bash console.

STEP 3:

Push your code from version control

This will push from (in my example) github to your pythonanywhere. You will also do something similar with your version control system.

STEP 4:

Setup a virtual environment then do your dependencies.


STEP 5:

Now to link your uploaded code and libraries with pythonanywhere. Leave the consoles tab and head over to the web tab.

Add a new web app.

Select manual configuration and proceed to select your python distro.

Enter name of your virtual env




Enter source code directory.

One thing that's important here: your Django project (if you're using a recent version of Django) will have a file inside it called wsgi.py. This is not the one you need to change to set things up on PythonAnywhere -- the system here ignores that file.

Instead, the WSGI file to change is the one that has a link inside the "Code" section of the Web tab -- it will have a name something like /var/www/yourusername_pythonanywhere_com_wsgi.py or /var/www/www_yourdomain_com_wsgi.py.

Click on the WSGI file link, and it will take you to an editor where you can change it.
Delete everything except the Django section and then uncomment that section.

Ensure to change the path variable and the DJANGO_SETTINGS_MODULE.

After this, go to bash, navigate to manage.py and migrate. If you go back to Web Tab and hit reload. You should see your site there. If not, there will be links to your logs and you can surely check as to why its happening.

STEP 6:

To serve static files open your settings.py  and add this line:

STATIC_ROOT = os.path.join(BASE_DIR, "static")

Proceed to bash again and do a manage.py collectstatic. 

Finally, set up a static files mapping to get our web servers to serve out your static files for you.
  • Go to the Web tab on the PythonAnywhere dashboard
  • Go to the Static Files section
  • Enter the same URL as STATIC_URL in the url section (typically, /static/)
  • Enter the path from STATIC_ROOT into the path section (the full path, including /home/username/etc)
Then hit Reload and test your static file mapping by going to retrieve a known static file.


Comments

Post a Comment

Popular posts from this blog

Django & Firebase - A marriage of awesomeness

Requirements 1) Django (obviously) 2) Pyrebase (pip install pyrebase, you know the drill) So to give a better appreciation- I will first show you the HTML way then I'll proceed to show you how its done in Python. METHOD 1 : The HTML way Then you need to go to the firebase console. To setup a new project. After that you will see a web setup and you select that. Once selected you will see the config. It should be similar to this : Now that you have configured firebase, we now need to select the components which will be needed. depending on what you want for your app- you can now select the modules that you need. For us today, we will do the login authentication. Make sure you include firebase app first, so this is my screen: METHOD 2: Enter Python Open your dev environment and create a file named  pyrebase_settings within your django app folder. In it, you will have the following: Now, lets go to views.py!

ANDROID: support libraries must use the exact same version specification

Here's a way you can tackle this annoying issue. Click on the Gradle side pane, select Tasks->android->androidDependencies. Running it will generate a list of the dependencies and the versions and a quick scroll should help you! Pic below should help

Why I think the fiat money system is useless – PART 1 (How it all began)

The fiat money system came as a solution to the so called ‘problems’ of the gold standard.  We, at the time, thought we are now too cool for neo classical economics and started to vouch for classical economics (smh as if it raised us). But wait whoa! What am I talking about? I’m talking about money. Let me start off with a brief history of money. So we get on the same page. Let’s get into our imaginary time travel pod and let’s take a sneak peak of the past. By definition, money is a generally accepted medium of exchange. We started this medium of exchange by bartering. Bartering is a direct trade of goods and services - I'll give you a stone axe if you help me kill a mammoth - but such arrangements take time. You have to find someone who thinks an axe is a fair trade for having to face the 12-foot tusks on a beast that doesn't take kindly to being hunted. If that didn't work, you would have to alter the deal until someone agreed to the terms. O...