我对 Django 相当陌生,我已经安装并尝试在我的网络应用程序中使用脆皮表单。我在我安装的应用程序中添加了脆皮表单,后面有一个逗号。当我运行服务器时,我收到此错误:

Watching for file changes with StatReloader
Performing system checks...

Exception in thread Thread-3:
Traceback (most recent call last):
  File "c:\users\amart\django\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 "c:\users\amart\django\django\template\backends\django.py", line 121, in get_package_libraries
    module = import_module(entry[1])
  File "C:\Users\amart\AppData\Local\Programs\Python\Python36-32\lib\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 "C:\Users\amart\AppData\Local\Programs\Python\Python36-32\lib\site-packages\crispy_forms\templatetags\crispy_forms_field.py", line 10, in <module>
    from crispy_forms.utils import TEMPLATE_PACK, get_template_pack
  File "C:\Users\amart\AppData\Local\Programs\Python\Python36-32\lib\site-packages\crispy_forms\utils.py", line 11, in <module>
    from django.utils.lru_cache import lru_cache
ModuleNotFoundError: No module named 'django.utils.lru_cache'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\amart\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 916, in _bootstrap_inner
    self.run()
  File "C:\Users\amart\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "c:\users\amart\django\django\utils\autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "c:\users\amart\django\django\core\management\commands\runserver.py", line 117, in inner_run
    self.check(display_num_errors=True)
  File "c:\users\amart\django\django\core\management\base.py", line 390, in check
    include_deployment_checks=include_deployment_checks,
  File "c:\users\amart\django\django\core\management\base.py", line 377, in _run_checks
    return checks.run_checks(**kwargs)
  File "c:\users\amart\django\django\core\checks\registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "c:\users\amart\django\django\contrib\admin\checks.py", line 59, in check_dependencies
    for engine in engines.all():
  File "c:\users\amart\django\django\template\utils.py", line 90, in all
    return [self[alias] for alias in self]
  File "c:\users\amart\django\django\template\utils.py", line 90, in <listcomp>
    return [self[alias] for alias in self]
  File "c:\users\amart\django\django\template\utils.py", line 81, in __getitem__
    engine = engine_cls(params)
  File "c:\users\amart\django\django\template\backends\django.py", line 25, in __init__
    options['libraries'] = self.get_templatetag_libraries(libraries)
  File "c:\users\amart\django\django\template\backends\django.py", line 43, in get_templatetag_libraries
    libraries = get_installed_libraries()
  File "c:\users\amart\django\django\template\backends\django.py", line 108, in get_installed_libraries
    for name in get_package_libraries(pkg):
  File "c:\users\amart\django\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 'crispy_forms.templatetags.crispy_forms_field': No module named 'django.utils.lru_cache'

我不知道我的代码有什么问题。我发现其他一些用户在使用脆皮表单时遇到问题,但遇到了不同的错误。他们也无法从 python shell 导入脆皮形式,但这对我有用。即使我只在我安装的应用程序中添加了脆表单而不尝试将其应用到我的模板中,我仍然会收到错误消息。请让我知道我做错了什么。提前致谢。

最佳答案

您的 django-crispy-forms 版本已过时,已修复。
通过运行更新它:

pip install django-crispy-forms -U
-U 使 pip 将您当前的安装升级到最新安装。
您可以通过运行 pip install -h 找到更多相关信息

关于python - 姜戈脆皮形式,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55019076/

10-11 07:40