Django can be used to build great websites. But it is also really good for solving small problems quickly. Introducing a new series called “Django Nibbles”, to help you learn an aspect of Django say Templates through a short and simple problem. You can either solve the problem yourself or follow my step-by-step solution.
Q. Create a page that displays a binary clock showing the current time (when the page was loaded).
For instance, if the time is “23:55:02” then we should see:
○ ○ ○ ○ ○ ○ ○ ○ ● ● ○ ○ ● ● ○ ○ ○ ● ○ ● ● ● ○ ○
Each column represents a binary digit when read from top to bottom. For more details, read the Binary Clock wiki page.
Django Feature: Views
Time Given: 1 Hour
Go ahead. Try it yourself before reading further!
A. We will be using Python 3 (not 2.7) and Django 1.6 for solving this. Both are the latest versions at the time of writing.
Setting up the project
This section can be skipped if you know the basics of setting up a project in Django (which is simpler in Django 1.6)
On Linux command-line (indicated by the ‘$’ prompt), enter the following to create the
$ cd ~/projects $ django-admin.py startproject binclock $ cd binclock