1

カスタム コンテキスト プロセッサがあります。テンプレートにグローバルに渡す各リクエストで url_name を取得しています。

def custom_context_processor(request=None, sender=None, **kwargs):
    url_name = resolve(request.path).url_name
    .....

デバッグ モードが True の場合、すべて正常に動作します。しかし、False に設定すると、500 サーバー エラーが発生します。

しばらくテストした後、i18n URL パターンが debug=False で機能しないことがわかりました。

たとえば、localhost/ と記述した場合、デフォルトの言語に localhost/en としてリダイレクトされません。

しかし、私が localhost/en django を書くと、エラーは発生せず、期待どおりに動作します...

settings.py には次のものがあります。

ALLOWED_HOSTS = ['*']

テンプレートフォルダーに 404.html および 500.html エラーページがあります...

Django でエラー ログを有効にすると、次のようになります。

  Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.5-py2.7.egg/django/core/handlers/wsgi.py", line 255, in __call__
    response = self.get_response(request)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.5-py2.7.egg/django/core/handlers/base.py", line 156, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.5-py2.7.egg/django/core/handlers/base.py", line 224, in handle_uncaught_exception
    return callback(request, **param_dict)
  File "/Users/burakk/BurakWorks/Web/Shiftf5/Development/Eclipse/shiftf5/shiftf5/urls.py", line 64, in server_error
    response = render(request, "errors/index.html")
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.5-py2.7.egg/django/shortcuts/__init__.py", line 49, in render
    context_instance = RequestContext(request, current_app=current_app)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.5-py2.7.egg/django/template/context.py", line 179, in __init__
    self.update(processor(request))
  File "/Users/burakk/BurakWorks/Web/Shiftf5/Development/Eclipse/shiftf5/shiftf5/web/context_processors.py", line 31, in shiftf5_web
    url_name = resolve(request.path)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.5-py2.7.egg/django/core/urlresolvers.py", line 440, in resolve
    return get_resolver(urlconf).resolve(path)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.5-py2.7.egg/django/core/urlresolvers.py", line 334, in resolve
    raise Resolver404({'tried': tried, 'path': new_path})
Resolver404: {u'path': u'', u'tried': [[<RegexURLResolver <RegexURLPattern list> (admin:admin) ^admin/>], [<RegexURLResolver <module 'mediaalbums.urls' from '/Users/burakk/BurakWorks/Web/Shiftf5/Development/Eclipse/shiftf5/mediaalbums/urls.pyc'> (None:None) ^shiftf5_mediaalbums/>], [<RegexURLResolver <module 'django.conf.urls.i18n' from '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.5-py2.7.egg/django/conf/urls/i18n.pyc'> (None:None) ^i18n/>], [<RegexURLResolver <module 'taggit_autosuggest.urls' from '/Users/burakk/BurakWorks/Web/Shiftf5/Development/Eclipse/shiftf5/taggit_autosuggest/urls.pyc'> (None:None) ^taggit_autosuggest/>], [<RegexURLResolver <module 'grappelli.urls' from '/Users/burakk/BurakWorks/Web/Shiftf5/Development/Eclipse/shiftf5/grappelli/urls.pyc'> (None:None) ^grappelli/>], [<RegexURLPattern None ^favicon\.ico$>], [<RegexURLResolver <module 'ckeditor.urls' from '/Users/burakk/BurakWorks/Web/Shiftf5/Development/Eclipse/shiftf5/ckeditor/urls.pyc'> (None:None) ^ckeditor/>], [<RegexURLResolver <module 'rosetta.urls' from '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django_rosetta-0.7.1-py2.7.egg/rosetta/urls.pyc'> (None:None) ^rosetta/>], [<LocaleRegexURLResolver <RegexURLResolver list> (None:None) ^en/>], [<RegexURLPattern haystack_search_ml ^search/$>]]}
[13/Sep/2013 15:57:54] "GET / HTTP/1.1" 500 59
4

0 に答える 0