Django Crispy Forms

问题描述 投票:0回答:1

我是Django的新手,我已经安装并尝试在我的网络应用程序中使用crispy表单。我已经使用逗号将crispy_forms添加到我安装的应用程序之后。当我运行服务器时,我收到此错误:

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'

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

python django django-crispy-forms
1个回答
0
投票

问题已经解决了。我卸载了我使用的django版本并使用了:

pip install Django==2.1.7

感谢@YugandharChaudhari帮助我实现更改版本。

© www.soinside.com 2019 - 2024. All rights reserved.