Tag Archives: offline

Putting your Django website on offline / maintenance mode


Recently I was looking out for a good way to automate the process of putting my Django web application on maintenance / offline mode. I was working on a very large and dynamic project where the releases were very frequent and putting the project offline was completely a manual process. I was looking for a way to implement an application in Django which could perform the desired feature without making much changes to the already developed code (which was really huge).

I searched over internet and found some good Django applications, however I wanted to make it more generic, easy to customize and easy to integrate. So I decided to wrote my own Django plugin. Django provides a very important and useful feature of Middlewares, which I used to implement this Django plugin.

I started with creating a basic model to store the maintenance mode configuration:

The above model enables us to set the key flag to a Boolean value to check if the application is offline or not. The message field is used to create and display the custom message to the end-user while the application is offline.

next step was to create a small script to check the current status of the application, I called it offline.py:

The view which could handle the requests in case the application is offline for maintenance:

and finally a Middleware class, which will do the actual task of checking the application mode and processing the request accordingly:

This will require some basic templates for displaying messages to the end user and a notification to the admins.

As this complete setting will be handled by the admin of the website, we need to register our model with admin interface. So, I created a file admin.py:

The complete plug-in is available for download at: https://pypi.python.org/pypi/django-offline/0.1 with the details of installation. The github repository can be located at: https://github.com/ankitjaiswal07/django-offline