Host Django Website Application for Free in 5 Minutes

Learn how to Host Django Application for free at no cost. Simple and Easy step for hosting Django Website on the Internet without any money within 5 minutes. We will be using Python Anywhere for hosting our application on Cloud. Free Hosting – host without cost which has Simple and Ready to use Python Environment Interface which doesn’t need to install anything.

Live Demohttp://professionalcipher.pythonanywhere.com/ [Comment if not working]

Free Django Hosting in 5 Minutes

Deploying/Host Django Project on PythonAnywhere

Deploying a project on the server is more like setting up your local machine. We will be using virtualenv to create our Django Project Environment. In this tutorial, we will clone the project from Github which is a part of our Django CRM Tutorial.

Note Before getting started Sign up to PythonAnywhere and Create Your Account. We will be using Beginners’ plan which is a free plan.

Here’s an overview of the steps involved.

  1. Upload your code to Hosting Cloud Server
  2. Set up a virtualenv and install Django and any other requirements
  3. Set up your web app using the manual config option
  4. Add any other setup (static and media files, env variables)

Uploading Django Code to Hosting Server

Bash Console PythonAnywhere

As our code is ready on GitHub, we will clone it using Bash Console. Create a Bash Console by clicking on the Console Tab. You will see the terminal interface where you need to type git clone command.

# for example 
git clone https://github.com/studygyaan/Django-CRM-Project.git

Create VirtualEnv and Install Django and Dependencies

In your Bash console, create a virtualenv, named after your project name, and choose the version of Python you want to use like we are using now 3.7:

mkvirtualenv --python=/usr/bin/python3.7  mysite-virtualenv

You will see now in terminal like this – (mysite-virtualenv) $ which means virtualenv is activated. If you don’t then type bellow command which will activate it.

 workon  mysite-virtualenv 

Once the Virtual Env is activated. We will install Django inside it. There are two ways to do it. If you have requirements.txt file then you can use following

pip install -r requirements.txt

Or simply install Django and Required Libraries

pip install django 

Setting up your Django Web app and WSGI file

At this point, you need to be armed with 3 pieces of information:

  1. The path to your Django project’s top folder — the folder that contains “manage.py”, eg –  /home/myusername/mysite
  2. The name of your project (that’s the name of the folder that contains your settings.py), eg mysite
  3. The name of your virtualenv, eg mysite-virtualenv

Create a Web Application with Manual Config

Go to Web Tab and Click on it. You will see create a web application button, click on it and follow instructions.

Create a Web Application with Manual Config

NOTE: Make sure you choose Manual Configuration, not the “Django” option, that’s for new projects only.

Once your web app is created, scroll down and you need to add some paths like shown in bellow image.

PythonAnywhere Web App Configuration Free Hosting Django Python

Note – Maker sure you add folders’ names accordingly to your project names.
1. Code – /home/myusername/mysite/
2. Virtualenv – /home/username/.virtualenvs./mysite-virtualenv

Edit WSGI File to Point our Django Project to Server.

Edit WSGI of Django App

Click on the WSGI configuration file link. It will take you to your Hosted Django Project WSGI File. We need to add the following code. Just remove everything inside that file and paste the bellow code in it. Note you need to change bold code which your relevant paths.

import os
import sys

# assuming your Django settings file is at
# '/home/myusername/mysite/mysite/settings.py'
path = '/home/myusername/mysite'
if path not in sys.path:
     sys.path.insert(0, path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Save the file.

That’s it. Now the file step is to go to Web Tab and reload the web app and click on the link of your web app.

PythonAnywhere Web App

Disallowed Host Error

If you get Disallowed Host at Django let just add ‘*’ in ALLOWED_HOSTS in settings.py file and Reload the Web App.

 ALLOWED_HOSTS =['*'] 

4 Comments

Bibin ab

my application did not work. Should we need the app name to ‘app’.

Reply
Aroon

Hello Dear, i appreciate for making this series.
I have download your full project, and trying to run on local, it runs, but cant make super user, cant login, it gives some error give below:

return database_name == ‘:memory:’ or ‘mode=memory’ in database_name
TypeError: argument of type ‘WindowsPath’ is not iterable

I hope you will help me out. Thanks in advance 🙂

Reply

Leave a Reply

Your email address will not be published. Required fields are marked *