All Projects → fabiocaccamo → Django Maintenance Mode

fabiocaccamo / Django Maintenance Mode

Licence: mit
shows a 503 error page when maintenance-mode is on. 🚧 🛠

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Django Maintenance Mode

Django Rest Framework Docs
Document Web APIs made with Django Rest Framework
Stars: ✭ 607 (+203.5%)
Mutual labels:  django, pypi
Webterminal
ssh rdp vnc telnet sftp bastion/jump web putty xshell terminal jumpserver audit realtime monitor rz/sz 堡垒机 云桌面 linux devops sftp websocket file management rz/sz otp 自动化运维 审计 录像 文件管理 sftp上传 实时监控 录像回放 网页版rz/sz上传下载/动态口令 django
Stars: ✭ 1,124 (+462%)
Mutual labels:  maintenance, django
Pyreportjasper
Python Reporting with JasperReports
Stars: ✭ 77 (-61.5%)
Mutual labels:  django, pypi
Django Rest Auth
This app makes it extremely easy to build Django powered SPA's (Single Page App) or Mobile apps exposing all registration and authentication related functionality as CBV's (Class Base View) and REST (JSON)
Stars: ✭ 2,289 (+1044.5%)
Mutual labels:  django
Repoll
Redis管理平台Repoll,现已开源,基于redis3.x,支持单机、哨兵以及集群模式
Stars: ✭ 196 (-2%)
Mutual labels:  django
My blog
My Django Blog
Stars: ✭ 198 (-1%)
Mutual labels:  django
Django Behaviors
Easily integrate common behaviors for Django models, e.g. Timestamps, Publishing, Authoring, Editing and more.
Stars: ✭ 201 (+0.5%)
Mutual labels:  django
Rengorum
🚀 Forum app built in React, Redux & Django
Stars: ✭ 194 (-3%)
Mutual labels:  django
42 corrections
Corrections files of 42 School
Stars: ✭ 198 (-1%)
Mutual labels:  django
Django Secretballot
🗳 django voting application that allows semi-anonymous voting
Stars: ✭ 197 (-1.5%)
Mutual labels:  django
Django Easy Timezones
Easy timezones for Django based on GeoIP
Stars: ✭ 195 (-2.5%)
Mutual labels:  django
Composer Patches
Applies a patch from a local or remote file to any package that is part of a given composer project. Patches can be defined both on project and on package level. Optional support for patch versioning, sequencing, custom patch applier configuration and composer command for testing/troubleshooting patches.
Stars: ✭ 196 (-2%)
Mutual labels:  maintenance
Vecihi
Build Your Own Photo Sharing App in 5 minutes
Stars: ✭ 199 (-0.5%)
Mutual labels:  django
Django Sspanel
用diango开发的shadowsocks/V2ray面板
Stars: ✭ 2,538 (+1169%)
Mutual labels:  django
Drf Access Policy
Declarative access policies/permissions modeled after AWS' IAM policies.
Stars: ✭ 200 (+0%)
Mutual labels:  django
Pyquickinstall
⚡️⚡️⚡️超好用的pip下载加速工具,谁用谁知道!
Stars: ✭ 195 (-2.5%)
Mutual labels:  pypi
Okuna Api
🤖 The Okuna Social Network API
Stars: ✭ 200 (+0%)
Mutual labels:  django
Pan Os Python
The PAN-OS SDK for Python is a package to help interact with Palo Alto Networks devices (including physical and virtualized Next-generation Firewalls and Panorama). The pan-os-python SDK is object oriented and mimics the traditional interaction with the device via the GUI or CLI/API.
Stars: ✭ 194 (-3%)
Mutual labels:  pypi
Django Webpack Loader
Transparently use webpack with django
Stars: ✭ 2,327 (+1063.5%)
Mutual labels:  django
Django Job Portal
Job portal application using Django
Stars: ✭ 196 (-2%)
Mutual labels:  django

django-maintenance-mode

django-maintenance-mode shows a 503 error page when maintenance-mode is on.

It works at application level, so your django instance should be up.

It doesn't use database and doesn't prevent database access.

Installation

  1. Run pip install django-maintenance-mode or download django-maintenance-mode and add the maintenance_mode package to your project
  2. Add 'maintenance_mode' to settings.INSTALLED_APPS before custom applications
  3. Add 'maintenance_mode.middleware.MaintenanceModeMiddleware' to settings.MIDDLEWARE_CLASSES/settings.MIDDLEWARE as last middleware
  4. Add 'maintenance_mode.context_processors.maintenance_mode' to settings.CONTEXT_PROCESSORS
  5. Add your custom templates/503.html file
  6. Restart your application server

Configuration (optional)

Settings

All these settings are optional, if not defined in settings.py the default values (listed below) will be used.

# if True the maintenance-mode will be activated
MAINTENANCE_MODE = None
# by default, to get/set the state value a local file backend is used
# if you want to use the db or cache, you can create a custom backend
# custom backends must extend 'maintenance_mode.backends.AbstractStateBackend' class
# and implement get_value(self) and set_value(self, val) methods
MAINTENANCE_MODE_STATE_BACKEND = 'maintenance_mode.backends.LocalFileBackend'
# by default, a file named "maintenance_mode_state.txt" will be created in the settings.py directory
# you can customize the state file path in case the default one is not writable
MAINTENANCE_MODE_STATE_FILE_PATH = 'maintenance_mode_state.txt'
# if True admin site will not be affected by the maintenance-mode page
MAINTENANCE_MODE_IGNORE_ADMIN_SITE = False
# if True anonymous users will not see the maintenance-mode page
MAINTENANCE_MODE_IGNORE_ANONYMOUS_USER = False
# if True authenticated users will not see the maintenance-mode page
MAINTENANCE_MODE_IGNORE_AUTHENTICATED_USER = False
# if True the staff will not see the maintenance-mode page
MAINTENANCE_MODE_IGNORE_STAFF = False
# if True the superuser will not see the maintenance-mode page
MAINTENANCE_MODE_IGNORE_SUPERUSER = False
# list of ip-addresses that will not be affected by the maintenance-mode
# ip-addresses will be used to compile regular expressions objects
MAINTENANCE_MODE_IGNORE_IP_ADDRESSES = ()
# the path of the function that will return the client IP address given the request object -> 'myapp.mymodule.myfunction'
# the default function ('maintenance_mode.utils.get_client_ip_address') returns request.META['REMOTE_ADDR']
# in some cases the default function returns None, to avoid this scenario just use 'django-ipware'
MAINTENANCE_MODE_GET_CLIENT_IP_ADDRESS = None

Retrieve user's real IP address using django-ipware:

MAINTENANCE_MODE_GET_CLIENT_IP_ADDRESS = 'ipware.ip.get_ip'
# list of urls that will not be affected by the maintenance-mode
# urls will be used to compile regular expressions objects
MAINTENANCE_MODE_IGNORE_URLS = ()
# if True the maintenance mode will not return 503 response while running tests
# useful for running tests while maintenance mode is on, before opening the site to public use
MAINTENANCE_MODE_IGNORE_TESTS = False
# the absolute url where users will be redirected to during maintenance-mode
MAINTENANCE_MODE_REDIRECT_URL = None
# the template that will be shown by the maintenance-mode page
MAINTENANCE_MODE_TEMPLATE = '503.html'
# the path of the function that will return the template context -> 'myapp.mymodule.myfunction'
MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT = None
# the HTTP status code to send
MAINTENANCE_MODE_STATUS_CODE = 503
# the value in seconds of the Retry-After header during maintenance-mode
MAINTENANCE_MODE_RETRY_AFTER = 3600 # 1 hour

URLs

Add maintenance_mode.urls to urls.py if you want superusers able to set maintenance_mode using urls.

urlpatterns = [
    # ...
    url(r'^maintenance-mode/', include('maintenance_mode.urls')),
    # ...
]

Context Processors

Add maintenance_mode.context_processors.maintenance_mode to your context_processors list in settings.py if you want to access the maintenance_mode status in your templates.

TEMPLATES = [
    {
        # ...
        'OPTIONS': {
            'context_processors': [
                # ...
                'maintenance_mode.context_processors.maintenance_mode',
                # ...
            ],
        },
        # ...
    },
]

Context Managers

You can force a block of code execution to run under maintenance mode or not using context managers:

from maintenance_mode.core import maintenance_mode_off, maintenance_mode_on

with maintenance_mode_on():
    # do stuff
    pass

with maintenance_mode_off():
    # do stuff
    pass

Views

You can force maintenance mode on/off at view level using view decorators:

from maintenance_mode.decorators import force_maintenance_mode_off, force_maintenance_mode_on

@force_maintenance_mode_off
def my_view_a(request):
    # never return 503 response
    pass

@force_maintenance_mode_on
def my_view_b(request):
    # always return 503 response
    pass

Usage

Python

from maintenance_mode.core import get_maintenance_mode, set_maintenance_mode

set_maintenance_mode(True)

if get_maintenance_mode():
    set_maintenance_mode(False)

or

from django.core.management import call_command
from django.core.management.base import BaseCommand


class Command(BaseCommand):

    def handle(self, *args, **options):

        call_command('maintenance_mode', 'on')

        # call your command(s)

        call_command('maintenance_mode', 'off')



Templates

{% if maintenance_mode %}
<!-- html -->
{% endif %}

Terminal

Run python manage.py maintenance_mode <on|off>

(This is not Heroku-friendly because any execution of heroku run manage.py will be run on a separate worker dyno, not the web one. Therefore the state-file is set but on the wrong machine. You should use a custom MAINTENANCE_MODE_STATE_BACKEND.)

URLs

Superusers can change maintenance-mode using the following urls:

/maintenance-mode/off/

/maintenance-mode/on/

Testing

# create python virtual environment
virtualenv testing_django_maintanance_mode

# activate virtualenv
cd testing_django_maintanance_mode && . bin/activate

# clone repo
git clone https://github.com/fabiocaccamo/django-maintenance-mode.git src && cd src

# run tests
tox
# or
python setup.py test
# or
python -m django test --settings "tests.settings"

License

Released under MIT License.


See also

  • django-admin-interface - the default admin interface made customizable by the admin itself. popup windows replaced by modals. 🧙 ⚡

  • django-colorfield - simple color field for models with a nice color-picker in the admin. 🎨

  • django-extra-settings - config and manage typed extra settings using just the django admin. ⚙️

  • django-redirects - redirects with full control. ↪️

  • django-treenode - probably the best abstract model / admin for your tree based stuff. 🌳

  • python-benedict - dict subclass with keylist/keypath support, I/O shortcuts (base64, csv, json, pickle, plist, query-string, toml, xml, yaml) and many utilities. 📘

  • python-codicefiscale - encode/decode Italian fiscal codes - codifica/decodifica del Codice Fiscale. 🇮🇹 💳

  • python-fsutil - file-system utilities for lazy devs. 🧟‍♂️

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].