How to install django

This is a tutorial to create a simple django application and to host it on Webfaction with MySQL database. For this tutorial, we assumed you have python and virtualenv installed.

First we will create a django application on a local server (desktop) then we will migrate to Webfaction.

Installation

Create django project directory
$ mkdir djangoproject
$ cd djangoproject

Initialize virtual environment and install django

We are installing current version of django on Webfaction 1.11.5

$ python3 -m venv myvenv
source myvenv/bin/activate
(myvenv) ~$ pip install --upgrade pip
(myvenv) ~$ pip install django~=1.11.5

Create django application

Django creates a web framework, a skeleton for you to begin your customized web application. django-admin.py is a script that will create directories and files.

Let’s create a site called, “ispearfish”


(myvenv) ~/djangoproject$ django-admin startproject ispearfish .

djangoproject
├───manage.py
└───ispearfish
        settings.py
        urls.py
        wsgi.py
        __init__.py

update setting

You need to modify to fit your application requirements. For now, we will use the django’s default database, sqlite3. Go to settings.py and modify or add the following:

list of tz database time zones


TIME_ZONE = 'Pacific/Honolulu'
LANGUAGE_CODE = 'en-us'
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

CREATE DATABASE and START THE WEB SERVER

Create database for the ispearfish application.


(myvenv) ~/djangoproject$ python manage.py migrate
(myvenv) ~/djangoproject$ python manage.py runserver 0.0.0.0:8080

If you see this page, you have successfully create a django site with working database and web server!