Digital Labels Installation

richbs edited this page Jan 28, 2013 · 1 revision

You'll probably want a Python or Django developer to help you through this and or have some experience with developing Django. At least, a run through of the tutorials will be essential before grokking some of this:

Get our source code from Github and clone it into local directory called DigitalLabels

$ git clone -b pip-bundle ./DigitalLabels

Hop in to the directory:

$ cd ./DigitalLabels

Install DigitalLabels and its requirements:

$ pip install -r requirements.txt .

Hop out of the clone directory and clean it up:

$ cd ..
$ rm -rf ./DigitalLabels

Start your own Django project for your labels, called mylabels:

$ startproject mylabels

Brilliant! You've started your project. Hop into the project folder and let's look at the settings file in your favourite text editor (unless it's emacs).

$ vim ./mylabels/mylabels/

Here are some lines to add to the stock settings to get us up and running.

Filesystem and database

Let's give Django easy access to our local project folder. Stick this at the top of your

# Useful variable for quick local setup
import os
BASE_PATH = os.path.dirname(__file__)

Now we can set up the database and media folders. First, the database—find the DATABASES dictionary in your and edit it too look a bit like this:

'ENGINE': 'django.db.backends.sqlite3',  # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': BASE_PATH + '/digitallabels.db',  # Or path to database file if using sqlite3.

Here we are saying we want to get started with a little sqlite database, which is part of Python core, and create the file in the project directory.


Next thing to do is make sure we're able to deal with all the nice images we're going to upload into our digital labels.

First, the media root to which the images will be uploaded:

MEDIA_ROOT = BASE_PATH + '/media/'

Next, the URL path from which the images will be served:

MEDIA_URL = '/media/'

We add a new setting for the thumbnailing system, where all the variants of your uploaded images will be kept:

# Absolute filesystem path to the directory that will hold thumbnail files.
MEDIA_CACHE_ROOT = BASE_PATH + '/media/cache/'

Also, we need to set up a directory from where your CSS, JavaScript etc will be served, including the admin eye-candy. Find and edit these lines thus:

STATIC_ROOT = BASE_PATH + '/static/'

# URL prefix for static files.
# Example: ""
STATIC_URL = '/static/'


Plugging in the apps

Next we edit the INSTALLED_APPS tuple to include the required Django apps to make this whole show rock.

First, enable the admin. Where it says…

# Uncomment the next line to enable the admin:
# 'django.contrib.admin',

Do so…

# Uncomment the next line to enable the admin:

Then insert the following lines before the admin line:


Your INSTALLED_APPS setting could look as good as this:

    # Uncomment the next line to enable the admin:
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',

Miscellaneous settings

Stick these at the bottom of

Ensure your thumbnails are padded square to fit the square templates:

THUMBNAIL_ENGINE = 'labels.thumbs.PadEngine'

Give your admin site a custom heading:

GRAPPELLI_ADMIN_TITLE = "MyLabels Administration" 

If you want to hide the mouse cursor on the front end:

KIOSK_MODE = True # optional

Create appropriate media directories

In your mylabels project directory (cd mylabels) create the media directory:

$ mkdir mylabels/media

Create the database and superuser (follow the generated instructions):

$ python ./ syncdb

Hook up the URLS

Now we need to route the URLs to the appropriate views:

$ vim mylabels/

Enable, the admin interface by uncommenting the lines as indicated:

# Uncomment the next two lines to enable the admin:
from django.contrib import admin

And also the appropriate urlpatterns:

# Uncomment the next line to enable the admin:
url(r'^admin/', include(,

Insert the grappelli urlpatterns above the admin ones (for a fancy admin interface):

(r'^grappelli/', include('grappelli.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(,

Next, hook up the front end patterns for the labels. Insert after the admin patterns. Your urlpatterns tuple should look something like this:

urlpatterns = patterns('',
    (r'^grappelli/', include('grappelli.urls')),
    url(r'^admin/', include(,
    (r'^', include('labels.urls')),

Finally, during development, we need to serve up any images that are added to the system by administrators. Add these lines to the end of

from django.conf import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns += staticfiles_urlpatterns()
if settings.DEBUG:
    urlpatterns += patterns('',
        url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
            'document_root': settings.MEDIA_ROOT,

Finally, you should be able to start this whole shooting match:

$ python runserver

Then, you can hit up the URL:

Not much to see here. So, log in to the back end with the superuser you created.

From here, you can follow the user instructions in the README: