簡體   English   中英

姜戈脆皮形式

[英]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找到有關它的更多信息

問題已經解決。 我卸載了我擁有並使用的 django 版本:

pip install Django==2.1.7

感謝@YugandharChaudhari 幫助我意識到更改版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM