我正在尝试将Heroku中的堆栈从cedar-14
升级到heroku-16
,我很惊讶在部署应用程序时看到错误,但在本地运行python manage.py runserver
时却发现错误。
[2018-09-07 09:57:37 +0000] [8] [ERROR] Error handling request /en/
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py", line 111, in _get_response
resolver_match = resolver.resolve(request.path_info)
File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 520, in resolve
raise Resolver404({'tried': tried, 'path': new_path})
django.urls.exceptions.Resolver404: {'tried': [[<URLPattern '^robots\.txt$'>], [<URLPattern '^sitemap\.xml$'>], [<URLPattern '^sitemaps/static\.xml$'>], [<URLPattern '^sitemaps/destinations\.xml$'>], [<URLPattern '^sitemaps/routes_index\.xml$'>], [<URLPattern '^sitemaps/routes-(?P<orig_country>[A-Z]+)-(?P<dest_country>[A-Z]+)\.xml$' [name='routes_sitemap_index']>], [<URLPattern '^en/blog/$' [name='blog_en']>], [<URLPattern '^en/blog/(?P<slug>[A-Za-z1-9\-\(\)_]+)$' [name='blog_post']>], [<URLPattern '^../blog/.*'>], [<URLPattern '^index.*$'>], [<URLPattern '^content/cities$'>], [<URLPattern '^content/countries-and-cities$'>], [<URLPattern '^de/reisen/routen$'>], [<URLPattern '^en/travel/routes$'>], [<URLPattern '^.*grenchen.*'>], [<URLPattern '^content/imprint$'>], [<URLPattern '^en/content/imprint$'>], [<URLPattern '^content/terms$'>], [<URLPattern '^content/privacy$'>], [<URLPattern '^en/content/privacy$'>], [<URLPattern '^content/faq$'>], [<URLResolver <URLPattern list> (None:None) 'en-us/'>]], 'path': 'en/'}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/utils.py", line 66, in __getitem__
return self._engines[alias]
KeyError: 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/backends/django.py", line 121, in get_package_libraries
module = import_module(entry[1])
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/app/results/templatetags/formatting.py", line 806, in <module>
from django.core.urlresolvers import resolve, reverse
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/urlresolvers.py", line 4, in <module>
from django.utils.deprecation import RemovedInDjango20Warning
ImportError: cannot import name 'RemovedInDjango20Warning'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 108, in get_exception_response
response = callback(request, **{**param_dict, 'exception': exception})
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/views/defaults.py", line 45, in page_not_found
template = loader.get_template(template_name)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/loader.py", line 12, in get_template
engines = _engine_list(using)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/loader.py", line 66, in _engine_list
return engines.all() if using is None else [engines[using]]
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/utils.py", line 90, in all
return [self[alias] for alias in self]
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/utils.py", line 90, in <listcomp>
return [self[alias] for alias in self]
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/utils.py", line 81, in __getitem__
engine = engine_cls(params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/backends/django.py", line 25, in __init__
options['libraries'] = self.get_templatetag_libraries(libraries)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/backends/django.py", line 43, in get_templatetag_libraries
libraries = get_installed_libraries()
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/backends/django.py", line 108, in get_installed_libraries
for name in get_package_libraries(pkg):
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/backends/django.py", line 125, in get_package_libraries
"trying to load '%s': %s" % (entry[1], e)
django.template.library.InvalidTemplateLibrary: Invalid template library specified. ImportError raised when trying to load 'results.templatetags.formatting': cannot import name 'RemovedInDjango20Warning'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/utils.py", line 66, in __getitem__
return self._engines[alias]
KeyError: 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/backends/django.py", line 121, in get_package_libraries
module = import_module(entry[1])
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/app/results/templatetags/formatting.py", line 806, in <module>
from django.core.urlresolvers import resolve, reverse
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/urlresolvers.py", line 4, in <module>
from django.utils.deprecation import RemovedInDjango20Warning
ImportError: cannot import name 'RemovedInDjango20Warning'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 135, in handle
self.handle_request(listener, req, client, addr)
File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 176, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/wsgi.py", line 142, in __call__
response = self.get_response(request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py", line 78, in get_response
response = self._middleware_chain(request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 36, in inner
response = response_for_exception(request, exc)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 46, in response_for_exception
response = get_exception_response(request, get_resolver(get_urlconf()), 404, exc)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 111, in get_exception_response
response = handle_uncaught_exception(request, resolver, sys.exc_info())
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 129, in handle_uncaught_exception
return callback(request, **param_dict)
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/views/defaults.py", line 69, in server_error
template = loader.get_template(template_name)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/loader.py", line 12, in get_template
engines = _engine_list(using)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/loader.py", line 66, in _engine_list
return engines.all() if using is None else [engines[using]]
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/utils.py", line 90, in all
return [self[alias] for alias in self]
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/utils.py", line 90, in <listcomp>
return [self[alias] for alias in self]
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/utils.py", line 81, in __getitem__
engine = engine_cls(params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/backends/django.py", line 25, in __init__
options['libraries'] = self.get_templatetag_libraries(libraries)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/backends/django.py", line 43, in get_templatetag_libraries
libraries = get_installed_libraries()
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/backends/django.py", line 108, in get_installed_libraries
for name in get_package_libraries(pkg):
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/backends/django.py", line 125, in get_package_libraries
"trying to load '%s': %s" % (entry[1], e)
django.template.library.InvalidTemplateLibrary: Invalid template library specified. ImportError raised when trying to load 'results.templatetags.formatting': cannot import name 'RemovedInDjango20Warning'
cedar-14
和本地服务器都没有此错误?答案 0 :(得分:0)
一些有关类似错误的信息指出,Django版本可能存在冲突。
从伟大的贾斯汀·米切尔(Justin Mitchel)的video about how to upgrading Django 1.11 to Django 2.0 开始,我意识到reverse
方法已经发生了变化。引用视频中提到的article:
reverse
已移动# < 2.0 from django.core.urlresolvers import reverse # 2.0+ from django.urls import reverse
django.core.urlresolvers
现在就是django.urls
*请注意,不仅是reverse
方法,而且完整软件包(https://docs.djangoproject.com/en/dev/releases/2.0/)的[官方发行说明]也对此进行了解释:
django.core.urlresolvers
模块已被删除以支持其新功能 位置django.urls
。
我实际上正在移动此方法,正如在错误日志中可以看到的那样。 由于似乎以某种方式正在使用2个Django版本,因此我将代码修改为:
try:
from django.core.urlresolvers import reverse
except ImportError:
from django.urls import reverse
它终于可以工作了。
仍然不知道为什么使用Django 2.0 ...