简体   繁体   English

将django.dispatch.dispatcher从Django 0.96迁移到1.0.2

[英]Migrating django.dispatch.dispatcher from Django 0.96 to 1.0.2

How does one perform the following (Django 0.96) dispatcher hooks in Django 1.0? 如何在Django 1.0中执行以下(Django 0.96)调度程序挂钩?

import django.dispatch.dispatcher

def log_exception(*args, **kwds):
  logging.exception('Exception in request:')

# Log errors.
django.dispatch.dispatcher.connect(
  log_exception, django.core.signals.got_request_exception)

# Unregister the rollback event handler.
django.dispatch.dispatcher.disconnect(
  django.db._rollback_on_exception,
  django.core.signals.got_request_exception) 

Incidentally, this code is from Google's Article on Using Django on GAE . 顺便提一下,这段代码来自谷歌关于在GAE上使用Django的文章 Unfortunately the dispatch code in Django was rewritten between 0.96 and 1.0, and Google's example does not work with Django 1.0. 不幸的是,Django中的调度代码在0.96和1.0之间被重写,而Google的示例不适用于Django 1.0。

Of course, the Django people provided a helpful guide on how to do exactly this migration, but I'm not keen enough to figure it out at the moment. 当然,Django人员提供了有关如何完成此迁移的有用指南 ,但我现在还不足以弄明白这一点。 :o) :O)

Thanks for reading. 谢谢阅读。

Brian 布赖恩

The basic difference is that you no longer ask the dispatcher to connect you to some signal, you ask the signal directly. 基本区别在于您不再要求调度员将您连接到某些信号,您可以直接询问信号。 So it would look something like this: 所以它看起来像这样:

from django.core.signals import got_request_exception
from django.db import _rollback_on_exception

def log_exception(*args, **kwds):
  logging.exception('Exception in request:')

# Log errors.
got_request_exception.connect(log_exception)

# Unregister the rollback event handler.
_rollback_on_exception.disconnect(got_request_exception)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM