这么多小时后,我来找你,试图弄清楚为什么我的django设置不再起作用了。我向你想要的任何上帝发誓,昨晚我因此而没有入睡。
我想从Python 3.5切换到Python 3.7,因为我开始使用 f-strings ,并且由于Python 3.6提供了此功能,所以我想为什么不直接使用Python 3.7。另外,我希望我的2个域(mywebsite.fr和mywebsite.com)指向同一个django项目。到现在为止,只有mywebsite.fr才没有问题。
我将尽力向您详细解释为获得下面的代码而做的事情:
可能有一件有趣的事我注意到了:如果我访问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)
提前感谢您为我提供的建议!
现在它根本不起作用。我试图使其像以前一样在Python 3.5上运行,但没有成功。
答案 0 :(得分:1)
在将apache
与python 3.7.0.
一起使用
幸运的是,django 2.1.4
与python 3.6.6.
组合时可以正常工作
答案 1 :(得分:0)
好吧,我从没想过Django(2.1)的正式版本会成为问题,但是我们来了!在python 3.7
下创建新的虚拟环境时,我没有立即注意django的新版本。即使在此之后,我都认为它是一个稳定的版本,仅此而已。因此,在我的Ubuntu安装上也许出了点问题(但实际上我看不到什么),但是从django 2.1
降级到django 2.0
只是解决了我的问题!即使我在上面花了很多时间也很开心。请注意,它可以与Python 3.7
配合使用(就像我最初的愿望一样。)
感谢阅读!