{"id":13415750,"url":"https://github.com/fabiocaccamo/django-maintenance-mode","last_synced_at":"2025-05-14T10:09:30.469Z","repository":{"id":33417231,"uuid":"37062480","full_name":"fabiocaccamo/django-maintenance-mode","owner":"fabiocaccamo","description":":construction: :hammer_and_wrench: shows a 503 error page when maintenance-mode is on.","archived":false,"fork":false,"pushed_at":"2025-04-03T13:25:10.000Z","size":390,"stargazers_count":504,"open_issues_count":5,"forks_count":57,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-04-03T21:41:20.781Z","etag":null,"topics":["503","django","maintenance","maintenance-mode","pypi","python","service-unavailable"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fabiocaccamo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["fabiocaccamo"],"polar":"fabiocaccamo","ko_fi":"fabiocaccamo","liberapay":"fabiocaccamo","tidelift":"pypi/django-maintenance-mode","custom":["https://www.buymeacoffee.com/fabiocaccamo","https://www.paypal.me/fabiocaccamo"]}},"created_at":"2015-06-08T11:17:37.000Z","updated_at":"2025-04-03T13:23:43.000Z","dependencies_parsed_at":"2023-09-28T22:20:43.451Z","dependency_job_id":"d3c6d761-f53a-4579-9b1a-bf7c0e813714","html_url":"https://github.com/fabiocaccamo/django-maintenance-mode","commit_stats":{"total_commits":495,"total_committers":21,"mean_commits":"23.571428571428573","dds":0.2161616161616161,"last_synced_commit":"9b19dfffb8cee272f861d12b10a418002bb90712"},"previous_names":[],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiocaccamo%2Fdjango-maintenance-mode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiocaccamo%2Fdjango-maintenance-mode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiocaccamo%2Fdjango-maintenance-mode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiocaccamo%2Fdjango-maintenance-mode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fabiocaccamo","download_url":"https://codeload.github.com/fabiocaccamo/django-maintenance-mode/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248337085,"owners_count":21086949,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["503","django","maintenance","maintenance-mode","pypi","python","service-unavailable"],"created_at":"2024-07-30T21:00:51.832Z","updated_at":"2025-04-11T03:34:53.669Z","avatar_url":"https://github.com/fabiocaccamo.png","language":"Python","funding_links":["https://github.com/sponsors/fabiocaccamo","https://polar.sh/fabiocaccamo","https://ko-fi.com/fabiocaccamo","https://liberapay.com/fabiocaccamo","https://tidelift.com/funding/github/pypi/django-maintenance-mode","https://www.buymeacoffee.com/fabiocaccamo","https://www.paypal.me/fabiocaccamo"],"categories":["Third-Party Packages","Backend","Python"],"sub_categories":["General","Django"],"readme":"[![](https://img.shields.io/pypi/pyversions/django-maintenance-mode.svg?color=3776AB\u0026logo=python\u0026logoColor=white)](https://www.python.org/)\n[![](https://img.shields.io/pypi/djversions/django-maintenance-mode?color=0C4B33\u0026logo=django\u0026logoColor=white\u0026label=django)](https://www.djangoproject.com/)\n\n[![](https://img.shields.io/pypi/v/django-maintenance-mode.svg?color=blue\u0026logo=pypi\u0026logoColor=white)](https://pypi.org/project/django-maintenance-mode/)\n[![](https://static.pepy.tech/badge/django-maintenance-mode/month)](https://pepy.tech/project/django-maintenance-mode)\n[![](https://img.shields.io/github/stars/fabiocaccamo/django-maintenance-mode?logo=github\u0026style=flat)](https://github.com/fabiocaccamo/django-maintenance-mode/stargazers)\n[![](https://img.shields.io/pypi/l/django-maintenance-mode.svg?color=blue)](https://github.com/fabiocaccamo/django-maintenance-mode/blob/main/LICENSE.txt)\n\n[![](https://results.pre-commit.ci/badge/github/fabiocaccamo/django-maintenance-mode/main.svg)](https://results.pre-commit.ci/latest/github/fabiocaccamo/django-maintenance-mode/main)\n[![](https://img.shields.io/github/actions/workflow/status/fabiocaccamo/django-maintenance-mode/test-package.yml?branch=main\u0026label=build\u0026logo=github)](https://github.com/fabiocaccamo/django-maintenance-mode)\n[![](https://img.shields.io/codecov/c/gh/fabiocaccamo/django-maintenance-mode?logo=codecov)](https://codecov.io/gh/fabiocaccamo/django-maintenance-mode)\n[![](https://img.shields.io/codacy/grade/918668ac85e74206a4d8d95923548d79?logo=codacy)](https://www.codacy.com/app/fabiocaccamo/django-maintenance-mode)\n[![](https://img.shields.io/codeclimate/maintainability/fabiocaccamo/django-maintenance-mode?logo=code-climate)](https://codeclimate.com/github/fabiocaccamo/django-maintenance-mode/)\n[![](https://img.shields.io/badge/code%20style-black-000000.svg?logo=python\u0026logoColor=black)](https://github.com/psf/black)\n[![](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n\n# django-maintenance-mode\ndjango-maintenance-mode shows a 503 error page when **maintenance-mode** is **on**.\n\nIt works at application level, so your django instance should be up.\n\nIt doesn't use database and doesn't prevent database access.\n\n## Installation\n\n1. Run `pip install django-maintenance-mode` or [download django-maintenance-mode](http://pypi.python.org/pypi/django-maintenance-mode) and add the **maintenance_mode** package to your project\n2. Add `maintenance_mode` to `settings.INSTALLED_APPS` before custom applications\n3. Add `maintenance_mode.middleware.MaintenanceModeMiddleware` to `settings.MIDDLEWARE` as last middleware\n4. Add your custom `templates/503.html` file\n5. Restart your application server\n\n## Configuration (optional)\n\n### Settings\nAll these settings are optional, if not defined in `settings.py` the default values (listed below) will be used.\n\n```python\n# if True the maintenance-mode will be activated\nMAINTENANCE_MODE = None\n```\n\n```python\n# by default, to get/set the state value a local file backend is used\n# if you want to use the db or cache, you can create a custom backend\n# custom backends must extend 'maintenance_mode.backends.AbstractStateBackend' class\n# and implement get_value(self) and set_value(self, val) methods\nMAINTENANCE_MODE_STATE_BACKEND = \"maintenance_mode.backends.LocalFileBackend\"\n\n# alternatively it is possible to use the default storage backend\nMAINTENANCE_MODE_STATE_BACKEND = \"maintenance_mode.backends.DefaultStorageBackend\"\n\n# alternatively it is possible to use the static storage backend\n# make sure that STATIC_ROOT and STATIC_URL are also set\nMAINTENANCE_MODE_STATE_BACKEND = \"maintenance_mode.backends.StaticStorageBackend\"\n\n# alternatively it is possible to use the cache backend\n# you can use a custom cache backend by adding a `maintenance_mode` entry to `settings.CACHES`,\n# otherwise the default cache backend will be used.\nMAINTENANCE_MODE_STATE_BACKEND = \"maintenance_mode.backends.CacheBackend\"\n```\n\n```python\n# the fallback value that backends will return in case of failure\n# (actually this is only used by \"maintenance_mode.backends.CacheBackend\")\nMAINTENANCE_MODE_STATE_BACKEND_FALLBACK_VALUE = False\n```\n\n```python\n# by default, a file named \"maintenance_mode_state.txt\" will be created in the settings.py directory\n# you can customize the state file path in case the default one is not writable\nMAINTENANCE_MODE_STATE_FILE_PATH = \"maintenance_mode_state.txt\"\n```\n\n```python\n# if True admin site will not be affected by the maintenance-mode page\nMAINTENANCE_MODE_IGNORE_ADMIN_SITE = False\n```\n\n```python\n# if True anonymous users will not see the maintenance-mode page\nMAINTENANCE_MODE_IGNORE_ANONYMOUS_USER = False\n```\n\n```python\n# if True authenticated users will not see the maintenance-mode page\nMAINTENANCE_MODE_IGNORE_AUTHENTICATED_USER = False\n```\n\n```python\n# if True the staff will not see the maintenance-mode page\nMAINTENANCE_MODE_IGNORE_STAFF = False\n```\n\n```python\n# if True the superuser will not see the maintenance-mode page\nMAINTENANCE_MODE_IGNORE_SUPERUSER = False\n```\n\n```python\n# list of ip-addresses that will not be affected by the maintenance-mode\n# ip-addresses will be used to compile regular expressions objects\nMAINTENANCE_MODE_IGNORE_IP_ADDRESSES = ()\n```\n\n```python\n# the path of the function that will return the client IP address given the request object -\u003e 'myapp.mymodule.myfunction'\n# the default function ('maintenance_mode.utils.get_client_ip_address') returns request.META['REMOTE_ADDR']\n# in some cases the default function returns None, to avoid this scenario just use 'django-ipware'\nMAINTENANCE_MODE_GET_CLIENT_IP_ADDRESS = None\n```\nRetrieve user's real IP address using [`django-ipware`](https://github.com/un33k/django-ipware):\n```python\nMAINTENANCE_MODE_GET_CLIENT_IP_ADDRESS = \"ipware.ip.get_ip\"\n```\n\n```python\n# the path of the function that will return the response context -\u003e 'myapp.mymodule.myfunction'\nMAINTENANCE_MODE_GET_CONTEXT = None\n```\n\n```python\n# list of urls that will not be affected by the maintenance-mode\n# urls will be used to compile regular expressions objects\nMAINTENANCE_MODE_IGNORE_URLS = ()\n```\n\n```python\n# if True the maintenance mode will not return 503 response while running tests\n# useful for running tests while maintenance mode is on, before opening the site to public use\nMAINTENANCE_MODE_IGNORE_TESTS = False\n```\n\n```python\n# if True authenticated users will be logged out from their current session\nMAINTENANCE_MODE_LOGOUT_AUTHENTICATED_USER = False\n```\n\n```python\n# the absolute url where users will be redirected to during maintenance-mode\nMAINTENANCE_MODE_REDIRECT_URL = None\n```\n\n```python\n# the type of the response returned during maintenance mode, can be either \"html\" or \"json\"\nMAINTENANCE_MODE_RESPONSE_TYPE = \"html\"\n```\n\n```python\n# the template that will be shown by the maintenance-mode page\nMAINTENANCE_MODE_TEMPLATE = \"503.html\"\n```\n\n```python\n# the HTTP status code to send\nMAINTENANCE_MODE_STATUS_CODE = 503\n```\n\n```python\n# the value in seconds of the Retry-After header during maintenance-mode\nMAINTENANCE_MODE_RETRY_AFTER = 3600 # 1 hour\n```\n\n#### Context Processors\nAdd **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.\n\n```python\nTEMPLATES = [\n    {\n        # ...\n        \"OPTIONS\": {\n            \"context_processors\": [\n                # ...\n                \"maintenance_mode.context_processors.maintenance_mode\",\n                # ...\n            ],\n        },\n        # ...\n    },\n]\n```\n\n#### Logging\nYou can disable emailing 503 errors to admins while maintenance mode is enabled:\n\n```python\nLOGGING = {\n    \"filters\": {\n        \"require_not_maintenance_mode_503\": {\n            \"()\": \"maintenance_mode.logging.RequireNotMaintenanceMode503\",\n        },\n        ...\n    },\n    \"handlers\": {\n        ...\n    },\n    ...\n}\n```\n\n### Context Managers\nYou can force a block of code execution to run under maintenance mode or not using context managers:\n\n```python\nfrom maintenance_mode.core import maintenance_mode_off, maintenance_mode_on\n\nwith maintenance_mode_on():\n    # do stuff\n    pass\n\nwith maintenance_mode_off():\n    # do stuff\n    pass\n```\n\n### URLs\nAdd **maintenance_mode.urls** to `urls.py` if you want superusers able to set maintenance_mode using urls.\n\n```python\nurlpatterns = [\n    # ...\n    re_path(r\"^maintenance-mode/\", include(\"maintenance_mode.urls\")),\n    # ...\n]\n```\n\n### Views\nYou can force maintenance mode on/off at view level using view decorators:\n\n#### Function-based views\n\n```python\nfrom maintenance_mode.decorators import force_maintenance_mode_off, force_maintenance_mode_on\n\n@force_maintenance_mode_off\ndef my_view_a(request):\n    # never return 503 response\n    pass\n\n@force_maintenance_mode_on\ndef my_view_b(request):\n    # always return 503 response\n    pass\n```\n\n#### Class-based views\n\n```python\nfrom maintenance_mode.decorators import force_maintenance_mode_off, force_maintenance_mode_on\n\nurlpatterns = [\n    # never return 503 response\n    path(\"\", force_maintenance_mode_off(YourView.as_view()), name=\"my_view\"),\n\n    # always return 503 response\n    path(\"\", force_maintenance_mode_on(YourView.as_view()), name=\"my_view\"),\n]\n```\n\n## Usage\n\n### Python\n```python\nfrom maintenance_mode.core import get_maintenance_mode, set_maintenance_mode\n\nset_maintenance_mode(True)\n\nif get_maintenance_mode():\n    set_maintenance_mode(False)\n```\nor\n```python\nfrom django.core.management import call_command\nfrom django.core.management.base import BaseCommand\n\n\nclass Command(BaseCommand):\n\n    def handle(self, *args, **options):\n\n        call_command(\"maintenance_mode\", \"on\")\n\n        # call your command(s)\n\n        call_command(\"maintenance_mode\", \"off\")\n\n```\n\n### Templates\n```html\n{% if maintenance_mode %}\n\u003c!-- html --\u003e\n{% endif %}\n```\n\n### Terminal\n\nRun ``python manage.py maintenance_mode \u003con|off\u003e``\n\n*(**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`*.)*\n\n### URLs\nSuperusers can change maintenance-mode using the following urls:\n\n`/maintenance-mode/off/`\n\n`/maintenance-mode/on/`\n\n## Testing\n```bash\n# clone repository\ngit clone https://github.com/fabiocaccamo/django-maintenance-mode.git \u0026\u0026 cd django-maintenance-mode\n\n# create virtualenv and activate it\npython -m venv venv \u0026\u0026 . venv/bin/activate\n\n# upgrade pip\npython -m pip install --upgrade pip\n\n# install requirements\npip install -r requirements.txt -r requirements-test.txt\n\n# install pre-commit to run formatters and linters\npre-commit install --install-hooks\n\n# run tests\ntox\n# or\npython runtests.py\n# or\npython -m django test --settings \"tests.settings\"\n```\n\n## License\nReleased under [MIT License](LICENSE.txt).\n\n---\n\n## Supporting\n\n- :star: Star this project on [GitHub](https://github.com/fabiocaccamo/django-maintenance-mode)\n- :octocat: Follow me on [GitHub](https://github.com/fabiocaccamo)\n- :blue_heart: Follow me on [Twitter](https://twitter.com/fabiocaccamo)\n- :moneybag: Sponsor me on [Github](https://github.com/sponsors/fabiocaccamo)\n\n## See also\n\n- [`django-admin-interface`](https://github.com/fabiocaccamo/django-admin-interface) - the default admin interface made customizable by the admin itself. popup windows replaced by modals. 🧙 ⚡\n\n- [`django-cache-cleaner`](https://github.com/fabiocaccamo/django-cache-cleaner) - clear the entire cache or individual caches easily using the admin panel or management command. 🧹✨\n\n- [`django-colorfield`](https://github.com/fabiocaccamo/django-colorfield) - simple color field for models with a nice color-picker in the admin. 🎨\n\n- [`django-extra-settings`](https://github.com/fabiocaccamo/django-extra-settings) - config and manage typed extra settings using just the django admin. ⚙️\n\n- [`django-redirects`](https://github.com/fabiocaccamo/django-redirects) - redirects with full control. ↪️\n\n- [`django-treenode`](https://github.com/fabiocaccamo/django-treenode) - probably the best abstract model / admin for your tree based stuff. 🌳\n\n- [`python-benedict`](https://github.com/fabiocaccamo/python-benedict) - dict subclass with keylist/keypath support, I/O shortcuts (base64, csv, json, pickle, plist, query-string, toml, xml, yaml) and many utilities. 📘\n\n- [`python-codicefiscale`](https://github.com/fabiocaccamo/python-codicefiscale) - encode/decode Italian fiscal codes - codifica/decodifica del Codice Fiscale. 🇮🇹 💳\n\n- [`python-fontbro`](https://github.com/fabiocaccamo/python-fontbro) - friendly font operations. 🧢\n\n- [`python-fsutil`](https://github.com/fabiocaccamo/python-fsutil) - file-system utilities for lazy devs. 🧟‍♂️\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabiocaccamo%2Fdjango-maintenance-mode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffabiocaccamo%2Fdjango-maintenance-mode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabiocaccamo%2Fdjango-maintenance-mode/lists"}