Package: django-maintenancemode-2
Current Version: 2.0.0This project makes it easy to put your Django site into “maintenance
mode”, or more technically, return an HTTP 503 response.This project differs slightly from other implementations in that the
maintenance mode flag is stored in your database versus settings or an
environment variable. If your site is deployed to multiple servers, the
centralized database-based maintenance flag makes it a snap to bring
them all up or down at once.Requirementsdjangodjango.contrib.sitesPre-RequisitesYou must have at least one Site entry in your databasebeforeinstalling django-maintenancemode-2.Supported Python Versions2.7, 3.xSupported Django Versions4.x use the latest version2.x >= 3.x, please use version 1.3.1< 2, please use version 1.1.9Installationpip installdjango-maintenancemode-2– or –Download django-maintenancemode-2 fromsource*optional: Enable a virtualenvRunpython setup.py installor addmaintenancemodeto your
PYTHONPATHSettings and Required ValuesEnsure theSites
Frameworkis enabled, and you have at least one entry in the Sites table.Addmaintenancemode.middleware.MaintenanceModeMiddlewareto yourMIDDLEWARE_CLASSESAddmaintenancemodeto yourINSTALLED_APPSRunpython manage.py migrateto create themaintenancemodetables.Run your project to automatically add themaintenancemodedatabase records.Add a 503.html template to the root of your templates directory, or
optionally add aMAINTENANCE_503_TEMPLATEpath to your 503.html
file’s location in settings.maintenancemodewill ignore any patterns beginning with the
default Django Admin url:^adminso you can turn it off. If you
use a custom url for admin, you may override the ignored admin
patterns by adding theMAINTENANCE_ADMIN_IGNORED_URLSlist in
settings. Example:['^my-custom-admin','^my-other-custom-admin']You can also block staff users, who by default are ignored by
maintenance mode, by settingMAINTENANCE_BLOCK_STAFFtoTrueUsageImage of django-maintenancemode-2Turning Maintenance ModeOnTo put a site into “Maintenance Mode”, check the “In Maintenance Mode”
checkbox and save in Django Admin under the “Maintenancemode” section.
The next time you visit the public side of the site, it will return a
503 if:You are not logged in as a superuser or staff userYou are not viewing a URL in the ignored patterns listYourREMOTE_ADDRdoes not appear in theINTERNAL_IPSsettingOr you can alternatively use thesetmaintenancemanagement command:# sets maintenance on for the current settings.SITE_ID
./manage.py setmaintenance on# sets maintenance on for sites 2 and 3
./manage.py setmaintenance on 2 3which can be useful forfabricdeployment scripts etc.Turning Maintenance ModeOffLog in, un-check the “In Maintenance Mode” checkbox and save.Or you can alternatively use thesetmaintenancemanagement command:# sets maintenance off for the current settings.SITE_ID
$ ./manage.py setmaintenance off# sets maintenance off for sites 2 and 3
$ ./manage.py setmaintenance off 2 3Testing and Sample ApplicationA “testproject” application is included, which also contains unit and
functional tests you can run viapython manage.py testfrom thetestprojectdirectory.You will need to runmanage.py migrateto create the test project
database.There are only two views in the testproject: - / - /ignored-pageTo seemaintenancemodein action, log into Django admin, and set the
maintenance mode to true. Log out, then visit the home page, and
instead, you’ll be greeted with the maintenance page.To havemaintenancemodeignore the “ignored-page” view, simply add
it’s url pattern to the Ignored URLs as:^ignored-page/$Now you should be able to visit theignored-pageview regardless of
the maintenancemode status. This is useful for contact or help pages you
still want people to be able to access while you’re working on other
parts of the site.Database migrations./manage.py migrateshould add the necessary tables.