Django 1.8 starters guide

Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.

Setting up locally

Make sure your vagrant box can access port 8000
Vagrantfile "forwarded_port", guest: 8000, host: 8000
config.vm.synced_folder "shared", "/home/vagrant/"

Installing dependencies

sudo apt-get install python-pip 
sudo pip install Django

Check versions installed

pip freeze

Go to the folder you want your web folder in startproject myproject
cd myproject
python migrate
python createsuperuser
python runserver

If you got no errors you can open your browser and view the starting django project

Sometimes you may need to install requests package

pip install requests

Setup your DB

python syncdb // depreciated in 1.9
python makemigrations
python migrate

Run django in the shell

python shell
exit() # to exit from shell

Creating your static files

python collectstatic

Typical folders to add:

/static/static_dirs/js/ changes

STATIC_URL = ‘/static/’

STATIC_ROOT = os.path.join(BASE_DIR, ‘static’, ‘static_root’)

    os.path.join(BASE_DIR, ‘static’, ‘static_dirs’),

        ‘DIRS’: [‘templates’], } ]

to add apps

to add middleware

If your app is already running and you need to stop it you can kill the process

lsof -i :8000
kill [PID]

Create your module

python startapp myapp

Using git ignore with django

Using MySQL

sudo apt-get install mysql-server
sudo apt-get install python-mysqldb
sudo service mysql start

To access mysql through command line

mysql -uroot -p

Create your DB manually (recommended utf-8)

Edit your file

    'default': {
        'ENGINE': 'django.db.backends.mysql', 
        'NAME': ‘dbname’,
        'USER': ‘root’,
        'PASSWORD': ‘root’,
        'HOST': 'localhost',
        'PORT': '3306',

Adding your favicon

pip install django-favicon file

) file

urlpatterns = patterns('',
    url(r'^', include('favicon.urls')),

Internal IPs

If you are using some tool like the debug toolbar then understand that your internal IP maybe different

To check what your IP is add this to your view:

print request.META.get('REMOTE_ADDR', None)

You can then see the IP that requests come from.
In my case it was so I updated my INTERNAL_IPS in as:

INTERNAL_IPS = ('', '', '', )


To run all tests

python test

To run only certain tests

python test myfolder/


To keep an eye on your tests coverage you can

sudo pip install coverage
coverage run --include='./*' test
coverage report


Useful additions:

1 comment for “Django 1.8 starters guide

  1. October 11, 2015 at 10:09 pm

    I’d also recommend virtualenv as a way to keep your set of libraries seperate from the OS set. Not strictly required when working in a vagrant, but it does mean you don’t have to sudo every library install.

Leave a Reply

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