跳转到主要内容

Django Python异常模型、管理器、日志处理器、中间件和excepthook

项目描述

安装

$ pip install django-command-exception

settings.py

INSTALLED_APPS+=['django_command_exception']

migrate

$ python manage.py migrate

模型

模型 列/字段
CommandException django_command_exception id,command,exc_class,exc_message,exc_traceback,created_at

示例

call_command

from django_command_exception.models import CommandException

try:
    call_command(name)
except Exception as e:
    CommandException(command=name).save()

BaseCommand

from django_command_exception.models import CommandException

class BaseCommand(BaseCommand):
    def execute(self, *args, **options):
        try:
            return super().execute(*args, **options)
        except Exception as e:
            CommandException(command=type(self).__module__.split('.')[-1]).save()

CommandExceptionMixin

from django_command_exception.mixins import CommandExceptionMixin

class Command(CommandExceptionMixin,BaseCommand):
    def handle(self, *args, **options):
        try:
            ...
        except Exception as e:
            self.error(e)

项目详情


下载文件

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

源代码分布

django_command_exception-1.0.2.tar.gz (2.6 kB 查看哈希)

源代码

支持者:

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面