python - Django 脆皮表格

标签 python django django-crispy-forms

我对 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 - Django 脆皮表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55019076/

相关文章:

python - 没有外键错误的django中间模型

python - 如何在 django 中设置该字段唯一?

django - 如何在 django-crispy-forms 中将表单字段分布在两列布局上?

Django 1.8 & Django Crispy Forms : Is there a simple, 实现日期选择器的简单方法?

python - 比较两个 OpenCV 图像/2D Numpy 数组

python - poloniex 中的 returnTradeHistory 总是返回空列表

python - 如何使用 MongoAlchemy 删除数据库的所有内容

django - 在 Django 中重置密码后对用户进行身份验证

Django:基于类的 View 无法呈现松脆的形式

python - 在类上定义魔法方法