Basic Django installation on Xubuntu 20.04

Django successful setup screen

A little over 14 years ago I was part of a small group that planned and developed a PHP application. Over the years I've made small changes to the application, but I realized a few years ago that what the application really needed was a complete overhaul. A few people offered to redo the application and one person actually got to the point of making our old code partially work with newer versions of PHP (one of the issues with the application). Ultimately even the best attempts were a band-aid solution to the real problem: the application needs to be simplified and re-written.

When we were planning the application one of the decisions we made was to use parts of a full-blown eCommerce suite as the starting point for our application. That decision not only added extra complexity to the coding/fixing/updating the application, but it added a lot of extra tables and fields that were not necessary. Using the eCommerce suite seemed like a good idea at the time since we could just dump database tables and use them in a "web" version, but we ended up dumping the eCommerce software a few years after we developed the application.

Since that time a lot has changed and PHP no longer seems like the best language for the application. While it's true that there are decent PHP frameworks like Laravel, Python and Django seem like a better choice since:

  1. Python is extremely popular among developers today
  2. Python is easy to use
  3. At work we already have a project that uses the Django framework
  4. I know of at least one existing volunteer that has Django experience

With that in mind I decided to learn Django. Unfortunately almost every programming tutorial tends to start with "here's how to start on Windows or Mac OS." Linux programming tutorials either tend to be aimed at experts (or people who code frequently) or simply non-existant/outdated.

One Youtuber started his introduction with "you should do this on Linux, but we're going to install Django on Windows because it's more popular." Talk about disappointing. I found another set of Django Youtube videos from 2013 by Mike Hibbert: https://www.youtube.com/watch?v=oT1A1KKf0SI&list=PLxxA5z-8B2xk4szCgFmgonNcCboyNneMD . While the information is outdated, the first video provided me with enough information that I was able to install my first Django project on Xubuntu 20.04.

I'm learning, so not everything I'm recording here might be necessary, this is just what worked for me.

First install python. Initially I tried apt install python, but this appears to flag a transitional package that installs a 2.7 version of python and I knew I wanted python3, so I removed the package and installed the following packages:

sudo apt install python3 python3-php python3-django python3-setuptools

Mike mentions installing python-setuptools and using easy_install to install virtualenv. This might have worked in 2013, but it didn't work for me with the python3-setuptools package. Instead I simply installed virtualenv.

sudo apt install virtualenv

The next step in Mike's tutorial is creating a virtual environment for the project. Mike uses the --no-site-packages switch, but this switch has been deprecated in recent versions of virtualenv and is now the default behaviour. So the new way to create a basic virtual environment is (substitute django-basics for whatever you want to call the environment):

virtualenv django-basics

To activate and enter the environment:

source django-basics/bin/activate

This will switch the shell into the virtual environment. You would see a prompt similar to:

(django-basics) username@hostname:~$

Once in the virtual environment I found the easy_install script Mike mentioned earlier now works, so you can use it to install django within the virtual environment:

cd django-basics
easy_install Django

Note: you should be in the (django-basics) virtual environment when you do this and be sure to substitute your environment name for the name you cd into. The rest of Mike's video (creating a project) worked for me without issue. I'll post more as I work through all Mike's tutorials.

Thanks to Mike for this great start!