Sentry 定制 500 处理程序

发布于 2024-10-27 22:56:48 字数 3835 浏览 7 评论 0原文

我有一个定制的 500 hander 与哨兵一起使用。在我的 urls.py 文件中,我有:

def handler500(request):
    """
    500 error handler which includes ``request`` in the context.

    Templates: `500.html`
    Context: None
    """
    from django.template import Context, loader
    from django.http import HttpResponseServerError

    t = loader.get_template('500.html') # You need to create a 500.html template.
    return HttpResponseServerError(t.render(RequestContext(request)))

在我的 500.html 模板中:

{% extends "intranet/index.html" %}

{% block main_content %}
<h1>Internal Error!</h1>
<p>You've encountered an error, please try again in some time or file an 
error report if the problem persists. 
{% if request.sentry.id %}
You may reference this error as <strong>{{ request.sentry.id }}</strong>.
{% endif %}
</p>
{% endblock %}

这适用于我的本地计算机,但不适用于我的网络主机。 apache 日志包含此错误:

[Thu Mar 31 22:09:15 2011] [error] [client 127.0.0.1]     args = md5_constructor(u':'.join([urlquote(resolve_variable(var, context)) for var in self.vary_on])), referer: https://myurl.com/view/b4bddfa9da6d40fb8bad3e68393a8efb
[Thu Mar 31 22:09:15 2011] [error] [client 127.0.0.1]   File "/mypath/lib/python2.6/site-packages/django/template/__init__.py", line 630, in resolve_variable, referer: https://myurl.com/view/b4bddfa9da6d40fb8bad3e68393a8efb
[Thu Mar 31 22:09:15 2011] [error] [client 127.0.0.1]     return Variable(path).resolve(context), referer: https://myurl.com/view/b4bddfa9da6d40fb8bad3e68393a8efb
[Thu Mar 31 22:09:15 2011] [error] [client 127.0.0.1]   File "/mypath/lib/python2.6/site-packages/django/template/__init__.py", line 696, in resolve, referer: https://myurl.com/view/b4bddfa9da6d40fb8bad3e68393a8efb
[Thu Mar 31 22:09:15 2011] [error] [client 127.0.0.1]     value = self._resolve_lookup(context), referer: https://myurl.com/view/b4bddfa9da6d40fb8bad3e68393a8efb
[Thu Mar 31 22:09:15 2011] [error] [client 127.0.0.1]   File "/mypath/lib/python2.6/site-packages/django/template/__init__.py", line 749, in _resolve_lookup, referer: https://myurl.com/view/b4bddfa9da6d40fb8bad3e68393a8efb
[Thu Mar 31 22:09:15 2011] [error] [client 127.0.0.1]     raise VariableDoesNotExist("Failed lookup for key [%s] in %r", (bit, current)) # missing attribute, referer: https://myurl.com/view/b4bddfa9da6d40fb8bad3e68393a8efb
[Thu Mar 31 22:09:15 2011] [error] [client 127.0.0.1] TemplateSyntaxError: Caught VariableDoesNotExist while rendering: Failed lookup for key [request] in u'[{}, {\\'block\\': <Block Node: body. Contents: [<Text Node: \\'\\n<body>\\n<div id="page">\\n\\'>, <If node>, <Text Node: \\'\\n<div id="container" clas\\'>, <Block Node: container. Contents: [<Text Node: \\'\\n\\'>, <If node>, <Text Node: \\'\\n<div id="main_content" c\\'>, <If node>, <Text Node: \\'">\\n<div id="breadcrumbs">\\'>, <Block Node: main_content. Contents: [<Text Node: \\'\\n\\n<div id="actions">\\n\\'>, <Block Node: actions. Contents: [<Text Node: \\'\\n\\'>]>, <Text Node: \\'\\n</div>\\n<div id="content"\\'>, <Block Node: content. Contents: [<Text Node: \\'\\n\\'>]>, <Text Node: \\'\\n</div>\\n</div>\\n\\'>]>, <Text Node: \\'\\n<div style="clear: both;\\'>]>, <Text Node: \\'\\n</div>\\n\\'>, <If node>, <Text Node: \\'\\n<div style="clear: both;\\'>]>}, {\\'block\\': <Block Node: notifications. Contents: [<Text Node: \\'\\n    \\'>, <django.templatetags.cache.CacheNode object at 0xb3faa8c>, <Text Node: \\'\\n    \\'>]>}]', referer: https://myurl.com/view/b4bddfa9da6d40fb8bad3e68393a8efb

这让我发疯。任何建议将不胜感激

I have a custom 500 hander to use with sentry. In my urls.py file i have:

def handler500(request):
    """
    500 error handler which includes ``request`` in the context.

    Templates: `500.html`
    Context: None
    """
    from django.template import Context, loader
    from django.http import HttpResponseServerError

    t = loader.get_template('500.html') # You need to create a 500.html template.
    return HttpResponseServerError(t.render(RequestContext(request)))

And in my 500.html template:

{% extends "intranet/index.html" %}

{% block main_content %}
<h1>Internal Error!</h1>
<p>You've encountered an error, please try again in some time or file an 
error report if the problem persists. 
{% if request.sentry.id %}
You may reference this error as <strong>{{ request.sentry.id }}</strong>.
{% endif %}
</p>
{% endblock %}

This works on my local machine, but not on my webhost.
The apache logs contain this error:

[Thu Mar 31 22:09:15 2011] [error] [client 127.0.0.1]     args = md5_constructor(u':'.join([urlquote(resolve_variable(var, context)) for var in self.vary_on])), referer: https://myurl.com/view/b4bddfa9da6d40fb8bad3e68393a8efb
[Thu Mar 31 22:09:15 2011] [error] [client 127.0.0.1]   File "/mypath/lib/python2.6/site-packages/django/template/__init__.py", line 630, in resolve_variable, referer: https://myurl.com/view/b4bddfa9da6d40fb8bad3e68393a8efb
[Thu Mar 31 22:09:15 2011] [error] [client 127.0.0.1]     return Variable(path).resolve(context), referer: https://myurl.com/view/b4bddfa9da6d40fb8bad3e68393a8efb
[Thu Mar 31 22:09:15 2011] [error] [client 127.0.0.1]   File "/mypath/lib/python2.6/site-packages/django/template/__init__.py", line 696, in resolve, referer: https://myurl.com/view/b4bddfa9da6d40fb8bad3e68393a8efb
[Thu Mar 31 22:09:15 2011] [error] [client 127.0.0.1]     value = self._resolve_lookup(context), referer: https://myurl.com/view/b4bddfa9da6d40fb8bad3e68393a8efb
[Thu Mar 31 22:09:15 2011] [error] [client 127.0.0.1]   File "/mypath/lib/python2.6/site-packages/django/template/__init__.py", line 749, in _resolve_lookup, referer: https://myurl.com/view/b4bddfa9da6d40fb8bad3e68393a8efb
[Thu Mar 31 22:09:15 2011] [error] [client 127.0.0.1]     raise VariableDoesNotExist("Failed lookup for key [%s] in %r", (bit, current)) # missing attribute, referer: https://myurl.com/view/b4bddfa9da6d40fb8bad3e68393a8efb
[Thu Mar 31 22:09:15 2011] [error] [client 127.0.0.1] TemplateSyntaxError: Caught VariableDoesNotExist while rendering: Failed lookup for key [request] in u'[{}, {\\'block\\': <Block Node: body. Contents: [<Text Node: \\'\\n<body>\\n<div id="page">\\n\\'>, <If node>, <Text Node: \\'\\n<div id="container" clas\\'>, <Block Node: container. Contents: [<Text Node: \\'\\n\\'>, <If node>, <Text Node: \\'\\n<div id="main_content" c\\'>, <If node>, <Text Node: \\'">\\n<div id="breadcrumbs">\\'>, <Block Node: main_content. Contents: [<Text Node: \\'\\n\\n<div id="actions">\\n\\'>, <Block Node: actions. Contents: [<Text Node: \\'\\n\\'>]>, <Text Node: \\'\\n</div>\\n<div id="content"\\'>, <Block Node: content. Contents: [<Text Node: \\'\\n\\'>]>, <Text Node: \\'\\n</div>\\n</div>\\n\\'>]>, <Text Node: \\'\\n<div style="clear: both;\\'>]>, <Text Node: \\'\\n</div>\\n\\'>, <If node>, <Text Node: \\'\\n<div style="clear: both;\\'>]>}, {\\'block\\': <Block Node: notifications. Contents: [<Text Node: \\'\\n    \\'>, <django.templatetags.cache.CacheNode object at 0xb3faa8c>, <Text Node: \\'\\n    \\'>]>}]', referer: https://myurl.com/view/b4bddfa9da6d40fb8bad3e68393a8efb

This is driving me crazy. Any advice would be much appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一百个冬季 2024-11-03 22:56:48

开发和生产之间的设置绝对 100% 相同吗?

确保您的 TEMPLATE_CONTEXT_PROCESSORS 中有 django.core.context_processors.request

虽然我在您的模板中没有看到任何应该大声抱怨的内容,但您必须在另一个模板中有一些东西导致此问题的模板。

希望情况确实如此!

http://groups.google.com/group/ django-feincms/browse_thread/thread/8beccc194a6d6cf7/d843a074f300c9e9?#d843a074f300c9e9

http://daniel.hepper.net/blog/2010/11/how-to-fix-variabledoesnotexist-exception-in-django/

Are your settings absolutely 100% the same between dev and production?

Make sure you have django.core.context_processors.request in your TEMPLATE_CONTEXT_PROCESSORS

While i don't see anything in your template that should complain this loudly, you must have something in another template causing this problem.

Hope that's the case!

http://groups.google.com/group/django-feincms/browse_thread/thread/8beccc194a6d6cf7/d843a074f300c9e9?#d843a074f300c9e9

http://daniel.hepper.net/blog/2010/11/how-to-fix-variabledoesnotexist-exception-in-django/

勿忘心安 2024-11-03 22:56:48

我还因为另外两个原因(除了 TEPMLATE_CONTEXT_PROCESSORS 中缺少的部分)而出现了同样的错误:

  • 模型已过时 - 运行syncdb 并迁移,并且此错误消失了
  • urlconf 未在 url 中定义.py - 所有 urlconf 都被整齐地注释掉。

I had this same error appear for two additional (in addition to the missing part in the TEPMLATE_CONTEXT_PROCESSORS) reasons:

  • models were out of date - run syncdb and migrate and this went away
  • urlconf was not defined in the urls.py - all urlconfs were neatly commented out.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文