请我在这里需要你的帮助。我在我的应用程序中启用了 Django 国际化,即使调试为 False,它也能正常工作。但最近我尝试为我的服务器错误和找不到页面错误提供 500.html 和 404.html。现在,Internal Error: /
当您访问主页时,该应用程序会显示“”。示例localhost:8000
会给您服务器错误。但如果我手动输入网址,localhost:8000/en/
它就可以正常工作。任何人都可以在这方面为我照亮更多的光。以下是它在回溯时提供的错误。
[10/Jul/2020 09:49:40] DEBUG [django.template:872] Exception while resolving variable 'LANGUAGES' in template '500.html'.
Traceback (most recent call last):
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 100, in _get_response
resolver_match = resolver.resolve(request.path_info)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/urls/resolvers.py", line 558, in resolve
raise Resolver404({'tried': tried, 'path': new_path})
django.urls.exceptions.Resolver404: {'tried': [[<URLResolver <URLPattern list> (admin:admin) 'admin/'>], [<URLResolver <module 'accounts.urls' from '/home/trans/Documents/my_app/freight_app/accounts/urls.py'> (None:None) '^profile-accounts/admin/'>], [<URLResolver <URLPattern list> (None:None) 'en/'>]], 'path': ''}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 108, in get_exception_response
response = callback(request, **{**param_dict, 'exception': exception})
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/views/defaults.py", line 49, in page_not_found
body = template.render(context, request)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/backends/django.py", line 61, in render
return self.template.render(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 171, in render
return self._render(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 163, in _render
return self.nodelist.render(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 937, in render
bit = node.render_annotated(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 163, in _render
return self.nodelist.render(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 937, in render
bit = node.render_annotated(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/defaulttags.py", line 209, in render
nodelist.append(node.render_annotated(context))
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/defaulttags.py", line 309, in render
return nodelist.render(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 937, in render
bit = node.render_annotated(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/library.py", line 192, in render
output = self.func(*resolved_args, **resolved_kwargs)
File "/home/trans/Documents/my_app/freight_app/administration/templatetags/custom_admin_tags.py", line 16, in change_lang
url_parts = resolve(path)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/urls/base.py", line 24, in resolve
return get_resolver(urlconf).resolve(path)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/urls/resolvers.py", line 558, in resolve
raise Resolver404({'tried': tried, 'path': new_path})
django.urls.exceptions.Resolver404: {'tried': [[<URLResolver <URLPattern list> (admin:admin) 'admin/'>], [<URLResolver <module 'accounts.urls' from '/home/trans/Documents/my_app/freight_app/accounts/urls.py'> (None:None) '^profile-accounts/admin/'>], [<URLResolver <URLPattern list> (None:None) 'en/'>]], 'path': ''}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 829, in _resolve_lookup
current = current[bit]
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/context.py", line 83, in __getitem__
raise KeyError(key)
KeyError: 'LANGUAGES'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 835, in _resolve_lookup
if isinstance(current, BaseContext) and getattr(type(current), bit):
AttributeError: type object 'Context' has no attribute 'LANGUAGES'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 843, in _resolve_lookup
current = current[int(bit)]
ValueError: invalid literal for int() with base 10: 'LANGUAGES'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 850, in _resolve_lookup
(bit, current)) # missing attribute
django.template.base.VariableDoesNotExist: Failed lookup for key [LANGUAGES] in [{'True': True, 'False': False, 'None': None}, {}]
[10/Jul/2020 09:49:40] DEBUG [django.template:872] Exception while resolving variable 'request' in template '500.html'.
Traceback (most recent call last):
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 100, in _get_response
resolver_match = resolver.resolve(request.path_info)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/urls/resolvers.py", line 558, in resolve
raise Resolver404({'tried': tried, 'path': new_path})
django.urls.exceptions.Resolver404: {'tried': [[<URLResolver <URLPattern list> (admin:admin) 'admin/'>], [<URLResolver <module 'accounts.urls' from '/home/trans/Documents/my_app/freight_app/accounts/urls.py'> (None:None) '^profile-accounts/admin/'>], [<URLResolver <URLPattern list> (None:None) 'en/'>]], 'path': ''}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 108, in get_exception_response
response = callback(request, **{**param_dict, 'exception': exception})
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/views/defaults.py", line 49, in page_not_found
body = template.render(context, request)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/backends/django.py", line 61, in render
return self.template.render(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 171, in render
return self._render(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 163, in _render
return self.nodelist.render(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 937, in render
bit = node.render_annotated(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 163, in _render
return self.nodelist.render(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 937, in render
bit = node.render_annotated(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/defaulttags.py", line 209, in render
nodelist.append(node.render_annotated(context))
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/defaulttags.py", line 309, in render
return nodelist.render(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 937, in render
bit = node.render_annotated(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/library.py", line 192, in render
output = self.func(*resolved_args, **resolved_kwargs)
File "/home/trans/Documents/my_app/freight_app/administration/templatetags/custom_admin_tags.py", line 16, in change_lang
url_parts = resolve(path)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/urls/base.py", line 24, in resolve
return get_resolver(urlconf).resolve(path)
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/urls/resolvers.py", line 558, in resolve
raise Resolver404({'tried': tried, 'path': new_path})
django.urls.exceptions.Resolver404: {'tried': [[<URLResolver <URLPattern list> (admin:admin) 'admin/'>], [<URLResolver <module 'accounts.urls' from '/home/trans/Documents/my_app/freight_app/accounts/urls.py'> (None:None) '^profile-accounts/admin/'>], [<URLResolver <URLPattern list> (None:None) 'en/'>]], 'path': ''}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 829, in _resolve_lookup
current = current[bit]
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/context.py", line 83, in __getitem__
raise KeyError(key)
KeyError: 'request'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 835, in _resolve_lookup
if isinstance(current, BaseContext) and getattr(type(current), bit):
AttributeError: type object 'Context' has no attribute 'request'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 843, in _resolve_lookup
current = current[int(bit)]
ValueError: invalid literal for int() with base 10: 'request'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/trans/Documents/my_app/venv/lib/python3.6/site-packages/django/template/base.py", line 850, in _resolve_lookup
(bit, current)) # missing attribute
django.template.base.VariableDoesNotExist: Failed lookup for key [request] in [{'True': True, 'False': False, 'None': None}]
[10/Jul/2020 09:49:41] ERROR [django.request:228] Internal Server Error: /
[10/Jul/2020 09:49:41] ERROR [django.server:154] "GET / HTTP/1.1" 500 10352
[10/Jul/2020 09:49:41] INFO [django.server:154] "GET /static/css/bootstrap.css HTTP/1.1" 200 8192
[10/Jul/2020 09:49:42] INFO [django.server:154] "GET /en/jsi18n/ HTTP/1.1" 200 3223
[10/Jul/2020 09:49:42] INFO [django.server:154] "GET /static/css/font-awesome.min.css HTTP/1.1" 200 8192
[10/Jul/2020 09:49:42] INFO [django.server:154] "GET /static/css/style.css HTTP/1.1" 200 8192
[10/Jul/2020 09:49:42] INFO [django.server:154] "GET /static/images/500.png HTTP/1.1" 200 39523
[10/Jul/2020 09:49:42] INFO [django.server:154] "GET /static/images/logo.png HTTP/1.1" 200 8192
[10/Jul/2020 09:49:43] INFO [django.server:154] "GET /static/images/ajax-loader.gif HTTP/1.1" 200 8192
[10/Jul/2020 09:49:43] INFO [django.server:154] "GET /static/favicon.ico HTTP/1.1" 200 1150
[10/Jul/2020 09:49:43] INFO [django.server:154] "HEAD /static/favicon.ico HTTP/1.1" 200 1150