Skip to content

Posts from the ‘DJANGO’ Category


Pip and virtualenv on Windows

Install pip

Pip (Python Package Installer), official documentation for pip.

Usually Python3 comes with pip preinstalled. If you get an error “pip command not found”, use the following command to install pip:

Download, make sure you’re saving file to Desktop

In your Command Prompt navigate to Desktop

cd Desktop



Now pip should work system wide.


In your Command Prompt enter:

pip install virtualenv

Launch virtualenv

In your Command Prompt navigate to your project:

cd your_project

Within your project:

virtualenv env

Activate your virtualenv:

on Windows, virtualenv creates a batch file


to activate virtualenv on Windows, activate script is in the Scripts folder :




Another way to install pip

Save the “” file to your desktop form

In your Command Prompt navigate to Desktop:

cd Desktop



install pip:

easy_install pip


DJANGO Cheat Sheet

Set up the virtual environment and create a new project in DJANGO.

virtualenv --python=python3.6 venv
virtualenv venv

source venv/bin/activate


pip3 install django
pip3 install pillow
django-admin startproject [project name]

Verify project creation and start DJANGO server.

# Navigate to the newly created project folder.
. python3 runserverall

# Create a superuser
python3 createsuperuser [username]

# Test Server
python3 runserver

Creating a Django App

1. Open terminal and navigate to django project folder (where exists)
2. django-admin startapp [app name] # use pluralised names, e.g. posts
3. Navigate to new app folder.
4. Create new subfolder called “templates”
5. Navigate to new templates folder.
6. Create new subfolder called same name as your app (e.g. posts)
7. Go back to project folder
8. Open project and add “from [appname] import views”. Then add url path for new view.
e.g. url(r’^$’, views.home, name=‘home’)
9. Open and add:
def home(request):
return render(request, ‘posts/home.html’)
10. Navigate to projectfolder\appfolder\templates\appfolder
11. Create new file ‘home.html’
12. Go to project folder and open Scroll down to INSTALLED_APPs and add
‘appname’, to the end of the list of apps.

Connecting PostgreSQL to a Django Project

1. Create a new database in PostgreSQL, and assign a DB user with admin privileges
2. Go to project and scroll down to DATABASES section. Replace with:

 'default': {
 'ENGINE': 'django.db.backends.postgresql',
 'NAME': ‘[databasename]’,
 'USER': ‘[username]’,
 'PASSWORD': ‘[password]’,
 'HOST': '',
 'PORT': '5432',

3. Scroll down to TIMEZONE and replace code. e.g. TIME_ZONE = ‘Australia/Perth’