经过这么多小时,我来找你,试图弄清楚为什么我的 django 设置不再工作了。我向你想要的上帝发誓,我昨晚没有因此而睡觉。
我想从 Python 3.5 切换到 Python 3.7,因为我开始使用f 字符串,并且由于这个功能在 Python 3.6 中可用,我想为什么不直接使用 Python 3.7。另外,我希望我的 2 个域(mywebsite.fr 和 mywebsite.com(指向同一个 django 项目。到目前为止,只有 mywebsite.fr 没有问题。
我将尝试尽可能准确地向您解释我为获得以下可怕的代码所做的工作:
- 我的安装是在 Ubuntu 16.04 上,
- 我对 Ubuntu 安装程序上原生安装的 Python 版本做了一些混乱。我终于成功地正确安装了(我认为(Python 3.7,
- 我真的很难配置/制作/安装适当的mod_wsgi,
- 我使用 venv 进行我的 django 设置(下面称为m2gvenvprod(,
- 我正在使用mod_wgsi及其关联的守护程序模式,
- 通过我阅读的所有内容,我确信我在 apache2 中针对每个网站/域的 conf 都是正确的(在可用的站点中(,
- 在这里,在尝试了我在互联网上找到的有关我的问题的所有内容的任何组合之后.log下面出现 apache2 错误。我无法理解该日志。我不明白为什么 django 不是一个有效的密钥。我现在什么都不知道...真的很绝望。
我注意到一件事可能很有趣:如果我转到 mywebsite.com:错误 500。但是如果我去 mywebsite.com/admin,我会被重定向到 mywebsite.com/admin/login/?next=/admin/:所以,一定有什么东西还在工作,嗯?
Traceback (most recent call last):
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/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 "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/backends/django.py", line 121, in get_package_libraries
module = import_module(entry[1])
File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django_libs/templatetags/libs_tags.py", line 6, in <module>
from django.template.base import TOKEN_BLOCK, TOKEN_VAR
ImportError: cannot import name 'TOKEN_BLOCK' from 'django.template.base' (/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/base.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/core/handlers/base.py", line 156, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/core/handlers/base.py", line 154, in _get_response
response = response.render()
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/response.py", line 106, in render
self.content = self.rendered_content
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/response.py", line 81, in rendered_content
template = self.resolve_template(self.template_name)
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/response.py", line 63, in resolve_template
return select_template(template, using=self.using)
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/loader.py", line 38, in select_template
engines = _engine_list(using)
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/loader.py", line 66, in _engine_list
return engines.all() if using is None else [engines[using]]
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/utils.py", line 90, in all
return [self[alias] for alias in self]
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/utils.py", line 90, in <listcomp>
return [self[alias] for alias in self]
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/utils.py", line 81, in __getitem__
engine = engine_cls(params)
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/backends/django.py", line 25, in __init__
options['libraries'] = self.get_templatetag_libraries(libraries)
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/backends/django.py", line 43, in get_templatetag_libraries
libraries = get_installed_libraries()
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/backends/django.py", line 108, in get_installed_libraries
for name in get_package_libraries(pkg):
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/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 'django_libs.templatetags.libs_tags': cannot import name 'TOKEN_BLOCK' from 'django.template.base' (/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/base.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/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 "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/backends/django.py", line 121, in get_package_libraries
module = import_module(entry[1])
File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django_libs/templatetags/libs_tags.py", line 6, in <module>
from django.template.base import TOKEN_BLOCK, TOKEN_VAR
ImportError: cannot import name 'TOKEN_BLOCK' from 'django.template.base' (/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/base.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/utils/deprecation.py", line 91, in __call__
response = response or self.get_response(request)
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/core/handlers/exception.py", line 36, in inner
response = response_for_exception(request, exc)
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/core/handlers/exception.py", line 90, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/core/handlers/exception.py", line 129, in handle_uncaught_exception
return callback(request, **param_dict)
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/views/defaults.py", line 69, in server_error
template = loader.get_template(template_name)
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/loader.py", line 12, in get_template
engines = _engine_list(using)
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/loader.py", line 66, in _engine_list
return engines.all() if using is None else [engines[using]]
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/utils.py", line 90, in all
return [self[alias] for alias in self]
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/utils.py", line 90, in <listcomp>
return [self[alias] for alias in self]
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/utils.py", line 81, in __getitem__
engine = engine_cls(params)
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/backends/django.py", line 25, in __init__
options['libraries'] = self.get_templatetag_libraries(libraries)
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/backends/django.py", line 43, in get_templatetag_libraries
libraries = get_installed_libraries()
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/backends/django.py", line 108, in get_installed_libraries
for name in get_package_libraries(pkg):
File "/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/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 'django_libs.templatetags.libs_tags': cannot import name 'TOKEN_BLOCK' from 'django.template.base' (/home/krazymax/django/M2Gproject/m2gvenvprod/lib/python3.7/site-packages/django/template/base.py)
提前感谢您为我提供的建议!
编辑 1
现在它根本不起作用。我试图让它像以前一样在Python 3.5上运行,但没有成功。
好吧,我从没想过 Django (2.1( 的正式发布会成为问题所在,但我们来了!在python 3.7
下创建新的虚拟环境时,我没有立即关注新版本的django。即使在之后,我也认为它是一个稳定的版本,仅此而已。所以也许我的 Ubuntu 安装出了问题(但真的我看不出是什么(,但从django 2.1
降级到django 2.0
刚刚解决了我的问题!即使我花太多时间在这上面,也很高兴。请注意,它适用于Python 3.7
(就像我最初的愿望一样(。
感谢您的阅读!
我在使用apache
时也遇到了问题python 3.7.0.
幸运的是,当与python 3.6.6.
结合使用时,django 2.1.4
正常工作