2011-03-31 32 views
5

我有一個自定義的500漢奸與哨兵一起使用。在我的urls.py文件我有:哨兵定製500處理程序

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 

這讓我瘋狂。任何意見將不勝感激

回答

2

你的設置絕對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/

+0

有幾個不同的設置,但這只是調試等的東西,他們在我導入不同的local_settings文件。 – zsquare 2011-03-31 18:12:42

+1

另外,我在我的設置中有「django.core.context_processors.request」。有任何想法嗎?我在邊緣,任何一分鐘都可以甩掉我的頭髮:D – zsquare 2011-03-31 18:22:26

+0

當然!這隻發生在500錯誤? :( – 2011-03-31 18:55:48

0

我有出現同樣的錯誤了兩個額外的(除了在TEPMLATE_CONTEXT_PROCESSORS缺少的部分)的原因:

  • 模式已經過時 - 運行執行syncdb並遷移,這就消失了
  • urlconf沒有在urls.py中定義 - 所有urlconf都被整齊地註釋掉了。