Django のエラー レポートをカスタマイズして、エラーを引き起こしたユーザーをメールで知らせてくれる方法はありますか?
問題があれば、私は Django 1.2 を使用しています。
よろしくお願いします!
Django のエラー レポートをカスタマイズして、エラーを引き起こしたユーザーをメールで知らせてくれる方法はありますか?
問題があれば、私は Django 1.2 を使用しています。
よろしくお願いします!
セントリーを使用したくない場合は、この単純なミドルウェアを使用して、ユーザー情報をエラー メールに添付できます。
# source: https://gist.github.com/646372
class ExceptionUserInfoMiddleware(object):
"""
Adds user details to request context on receiving an exception, so that they show up in the error emails.
Add to settings.MIDDLEWARE_CLASSES and keep it outermost(i.e. on top if possible). This allows
it to catch exceptions in other middlewares as well.
"""
def process_exception(self, request, exception):
"""
Process the exception.
:Parameters:
- `request`: request that caused the exception
- `exception`: actual exception being raised
"""
try:
if request.user.is_authenticated():
request.META['USERNAME'] = str(request.user.username)
request.META['USER_EMAIL'] = str(request.user.email)
except:
pass
このクラスを Django プロジェクトの下の任意の *.py ファイルに配置し、への参照を追加するだけMIDDLEWARE_CLASSES
です。つまり、プロジェクト ルート (settings.py がある場所) のファイル "middleware" に配置する場合は、単純にmiddleware.ExceptionUserInfoMiddleware
.