跳转到主要内容

django-maintenancemode 允许您临时关闭您的网站进行维护工作

项目描述

django-maintenancemode是一个中间件,允许您临时关闭您的网站进行维护工作。

具有员工凭证的已登录用户以及从Django的INTERNAL_IPS中定义的IP地址访问网站的用户仍然可以完全使用该网站。

Remco Wendt创作,以及一些优秀的贡献者

https://img.shields.io/pypi/v/django-maintenancemode.svg https://img.shields.io/pypi/dm/django-maintenancemode.svg https://img.shields.io/github/license/shanx/django-maintenancemode.svg https://img.shields.io/travis/shanx/django-maintenancemode.svg https://coveralls.io/repos/github/shanx/django-maintenancemode/badge.svg?branch=develop

工作原理

maintenancemode与Django中处理404或500错误的方式相同。它添加了一个可重写的handler503,你可以在你的主urls.py中覆盖它,或者你可以在你的模板目录中添加一个503.html

  • 如果用户已登录并且是工作人员,则不会显示维护页面。

  • 如果用户的IP在INTERNAL_IPS中,则不会显示维护页面。

  • 要覆盖默认视图(当启用维护模式时使用),你可以在你的ROOT_URLCONF中定义一个handler503变量,类似于定制其他错误处理程序的方式,例如:

    handler503 = 'example.views.maintenance_mode'

安装

  1. 要么从GitHub检出maintenancemode,要么使用pip安装。

    pip install django-maintenancemode
  2. maintenancemode添加到你的INSTALLED_APPS

    INSTALLED_APPS = (
        ...
        'maintenancemode',
    )
  3. MaintenanceModeMiddleware添加到MIDDLEWARE_CLASSES,确保它在AuthenticationMiddleware之后。

    MIDDLEWARE_CLASSES = (
        ...
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'maintenancemode.middleware.MaintenanceModeMiddleware',
    )
  4. 在你的项目的settings.py文件中添加一个名为MAINTENANCE_MODE的变量。

    MAINTENANCE_MODE = True  # Setting this variable to ``True`` activates the middleware.

    或将MAINTENANCE_MODE设置为False并使用maintenance命令。

    python ./manage.py maintenance <on|off>

请参阅示例应用程序。此应用程序用于手动测试此包的功能。这也可以作为一个很好的例子...

你需要Django 1.4或更高版本来运行它。它可能在旧版本上运行,但尚未进行测试。

配置

你可以在你的settings.py中设置各种可选配置选项。

# Enable / disable maintenance mode.
# Default: False
MAINTENANCE_MODE = True  # or ``False`` and use ``maintenance`` command

# Sequence of URL path regexes to exclude from the maintenance mode.
# Default: ()
MAINTENANCE_IGNORE_URLS = (
    r'^/docs/.*',
    r'^/contact'
)

许可协议

django-maintenancemode在BSD许可证下发布。

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

django-maintenancemode-0.11.7.tar.gz (10.1 kB 查看散列)

上传时间

构建分布

django_maintenancemode-0.11.7-py3-none-any.whl (12.2 kB 查看散列)

上传时间 Python 3

由以下支持