Tuesday, May 6, 2014

Python 3 Django 1.7 on Ubuntu 14.04 - Day 1

It's time to dive into learning Django.  I've been waiting until I could use Django with Python 3, and that time has now come. I'll be working on Ubuntu 14.04.  There is no python3-django package yet, so I'll give pip a try.  I also want to start with Django 1.7, so that I can learn the new built-in migrations instead of using South to update the data model.

Here is what I did to get started:
  • $ sudo aptitude install python3-pip
  • $ pip3 install --user https://www.djangoproject.com/download/1.7b3/tarball/
This created .local/lib/python3.4/site-packages and .local/bin directories in my $HOME and installed the Django egg in the .local site-packages directory and django-admin and django-admin.py in the .local/bin directory (see PEP 370).

Next I did:
  • $ python3
  • >>> import django
  • >>> print(django.get_version())
When the last statement returned 1.7b3 I knew I was in business. Trying to run django-admin, I realized that .local/bin was not in my PATH, so I added the following to the bottom of my .bashrc file:


export PATH

I also added the following to my .bash_aliases:

alias python='python3'

since Python 3 is what I use all the time now.

Starting a Django Project 

  • $ django-admin startproject checkitout
  • $ cd checkitout 
  • $ python3 manage.py runserver
Running this last step created a db.sqlite3 file in the checkitout directory - something new in Django 1.7 I believe.

At this point I created a bzr repository of this so that each step in the process from here on out can be easily rewound.  Each of these commands were run inside the top level checkitout directory:
  • bzr init
  • bzr add *
  • bzr ci -m "initial commit"
Next I setup a project on launchpad: https://launchpad.net/checkitout, and pushed up the initial commit:
  • bzr push lp:~jelkner/checkitout/trunk

Next Steps

  • $ django-admin startapp cioapp
  • edit cioapp/models.py
  • bzr add *
  • bzr ci -m "added app and first models"
  • bzr push lp:checkitout
  • edit checkitout/settings.py and added cioapp to INSTALLED_APPS
  • edit cioapp/admin.py and import and register models
  •  python3 manage.py migrate
This created the database tables and setup a superuser. I started the server again with:
  •  $ python3 manage.py runserver
pointed my browser at localhost:8080/admin and was able to login and see the tables. This brought me back to the point where my Django tutor, Chris Hedrick, left me off this afternoon, only now I've got Django 1.7 instead of the 1.6 we used earlier and I ran migrate instead of the syncdb from South. I'll finish by checking these last changes in, but I wonder what needs to get ignored by bzr to keep the database superuser info from being part of the repo? I'll have to start by asking Chris that tomorrow. A fine and productive day!


  1. People use this software to get perfect results as there are many software but they are useful. people always wants software with good features. All Software Download

  2. With the help of this software my language conversion problem can be solved easily. Thank you for the posting. www.ddlforall.blogspot.com

  3. I just wanted to let you know that your blog is brilliant! Thank you for putting all this effort into writing such rich, informative posts.
    Movers In Dubai
    International Movers

  4. I really appreciate the efforts you put into reviewing these useful resources.

    Also checkout our New Year 2017 Greetings new collections.

  5. I read blog thoroughly; it’s quite informative and well written post. You covered the topic very well. Thanks for sharing.
    Also checkout Pakistani chat rooms