【问题标题】:Sentry custom 500 handlerSentry 自定义 500 处理程序
【发布时间】:2011-07-27 01:58:16
【问题描述】:

我有一个自定义的 500 处理程序用于哨兵。在我的 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

这快把我逼疯了。任何建议将不胜感激

【问题讨论】:

    标签: django sentry


    【解决方案1】:

    您的设置在开发和生产之间是否完全 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/

    【讨论】:

    • 有一些不同的设置,但这只是调试等,它们位于我导入的不同 local_settings 文件中。
    • 另外,我的设置中有“django.core.context_processors.request”。有任何想法吗?我在边缘,我随时都会扯掉我的头发:D
    • 是的,仅在 500 页面上:'(
    • @Yuji'Tomita'Tomita “虽然我在您的模板中没有看到任何应该大声抱怨的内容”——模板尝试访问请求的属性:request.sentry.id
    • @zsquare django.core.context_processors 已移入 django 1.10,因此您现在需要 django.template.context_processors.request
    【解决方案2】:

    由于另外两个原因(除了TEPMLATE_CONTEXT_PROCESSORS 中的缺失部分),我出现了同样的错误:

    • 模型已过时 - 运行 syncdb 并迁移,这会消失
    • urlconf 没有在 urls.py 中定义 - 所有 urlconfs 都被整齐地注释掉了。

    【讨论】:

      猜你喜欢
      • 2020-09-14
      • 1970-01-01
      • 2017-12-18
      • 1970-01-01
      • 1970-01-01
      • 2023-04-11
      • 1970-01-01
      • 1970-01-01
      • 2010-11-03
      相关资源
      最近更新 更多