Activate Django's commands completion in Bash in 2 steps

Image: Python (License: CC-BY-SA Marcelo Canina)

Use TAB key complete feature in Linux Bash console

Last modified:
Tags: django, bash, complete


One of the best features of Django CMS is to have a wide set of commands to manage your web application from console.

One of the things that Linux users miss when working with a clean instance of Django is the ability of pressing the TAB key while writing a command to autocomplete them or presing TAB key twice to see all the available options.

In this tutorial we will enable such feature.

1. Install

Bash completion feature works by having a special script that uses the three builtin commands that are available to manipulate the programmable completion facilities, they are:

  • compgen
  • complete
  • compopt

For each program, there should be a script that uses them to properly enable the autocompletion feature, in Django this file is located in a special directory in main repository, not included in the delivered project by default, it is located at:

We first start by downloading this file into ~/local/share/django/extras directory, so in this case mkdir -p ~/local/share/django/extras would create the needed path.

Then downloading it and posting in the above directory wget -O ~/local/share/django/extras/

$ mkdir -p ~/local/share/django/extras
$ wget -O ~/
--2019-01-29 18:10:52--
Resolving (
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: [following]
--2019-01-29 18:10:53--
Resolving (
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2332 (2,3K) [text/plain]
Saving to: ‘/home/marcanuy/’

/home/marcanuy/django_bash_completion 100%[======================================================================>]   2,28K  --.-KB/s    in 0s      

2019-01-29 18:10:53 (10,4 MB/s) - ‘/home/marcanuy/’ saved [2332/2332]

2. Sourcing the file

Now we need to source the downloaded script, so the autocompletion is loaded into our console.

To make it available in our console we just run source ~/local/share/django/extras/

But there is a good chance that there is a virtual environment for each project, so depending in what type of virtual environment you are using you can load it at different places:

2.1 Manual

If you load your virtual environment manually, e.g.: source ~/.virtualenvs/MY-PROJECT/bin/activate, with a simple script in you project root like

source ~/.virtualenvs/MY-PROJECT/bin/activate
source ~/local/share/django/extras/

And then load your virtual environment by executing source

2.2. Using virtualenvwrapper

For virtualenvwrapper, add source ~/local/share/django/extras/ in the script.


After doing this simple installation, each type we press the TAB key while executing a command with python TAB it will load the list of available commands or autocomplete accordingly.


Marcelo Canina
I'm Marcelo Canina, a developer from Uruguay. I build websites and web-based applications from the ground up and share what I learn here.
comments powered by Disqus

This article shows how to add a bash completion script for Django's command.

Clutter-free software concepts.
Translations English Español

Except as otherwise noted, the content of this page is licensed under CC BY-NC-ND 4.0 . Terms and Policy.

Powered by SimpleIT Hugo Theme