简体   繁体   English

姜戈脆皮形式

[英]Django Crispy Forms

I am fairly new to Django and I have installed and am trying to use crispy forms in my web app.I have added crispy_forms to my installed apps with a comma after it.我对 Django 还很陌生,我已经安装并尝试在我的网络应用程序中使用脆皮表单。我在我安装的应用程序中添加了脆皮表单,后面有一个逗号。 When I run the server I get this error:当我运行服务器时,我收到此错误:

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'

I don't know what is wrong with my code.我不知道我的代码有什么问题。 I have found some other users who have issues using crispy forms but are getting a different error.我发现其他一些用户在使用脆皮表单时遇到问题,但遇到了不同的错误。 They were also unable to import crispy forms from the python shell but that is working for me.他们也无法从 python shell 导入脆皮形式,但这对我有用。 Even if I only add crispy forms to my installed apps without trying to apply it in my templates, I still get an error.即使我只向已安装的应用程序添加了脆表单,而没有尝试将其应用到我的模板中,我仍然会收到错误消息。 Please let me know what I'm doing wrong.请让我知道我做错了什么。 Thanks in advance.提前致谢。

Your version of django-crispy-forms is outdated, this has been fixed.您的 django-crispy-forms 版本已过时,已修复。 Update it by running:通过运行更新它:

pip install django-crispy-forms -U

-U makes pip upgrade your current installation to the newest. -U使 pip 将您当前的安装升级到最新的。 You can find more about it by running pip install -h您可以通过运行pip install -h找到有关它的更多信息

The problem has been solved.问题已经解决。 I uninstalled the django version I had and used:我卸载了我拥有并使用的 django 版本:

pip install Django==2.1.7

Thank you @YugandharChaudhari for helping me realize to change versions.感谢@YugandharChaudhari 帮助我意识到更改版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM