【问题标题】:My development server report this error after running it [closed]我的开发服务器在运行后报告此错误[关闭]
【发布时间】:2021-04-08 11:12:47
【问题描述】:

我的django项目运行开发服务器后报错:

每次运行开发服务器时都会出现此错误:
在运行服务器之前激活了虚拟环境。 如何解决它并让我的项目再次运行?

    Watching for file changes with StatReloader
    Exception in thread django-main-thread:
    Traceback (most recent call last):
      File "c:\users\bello\anaconda3\lib\threading.py", line 916, in _bootstrap_inner
        self.run()
      File "c:\users\bello\anaconda3\lib\threading.py", line 864, in run
        self._target(*self._args, **self._kwargs)
      File "C:\Users\bello\Envs\mosque-around-you\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
        fn(*args, **kwargs)
      File "C:\Users\bello\Envs\mosque-around-you\lib\site-packages\django\core\management\commands\runserver.py", line 110, in inner_run
        autoreload.raise_last_exception()
      File "C:\Users\bello\Envs\mosque-around-you\lib\site-packages\django\utils\autoreload.py", line 76, in raise_last_exception
        raise _exception[1]
      File "C:\Users\bello\Envs\mosque-around-you\lib\site-packages\django\core\management\__init__.py", line 357, in execute
        autoreload.check_errors(django.setup)()
      File "C:\Users\bello\Envs\mosque-around-you\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
        fn(*args, **kwargs)
      File "C:\Users\bello\Envs\mosque-around-you\lib\site-packages\django\__init__.py", line 24, in setup
        apps.populate(settings.INSTALLED_APPS)
      File "C:\Users\bello\Envs\mosque-around-you\lib\site-packages\django\apps\registry.py", line 114, in populate
        app_config.import_models()
      File "C:\Users\bello\Envs\mosque-around-you\lib\site-packages\django\apps\config.py", line 211, in import_models
        self.models_module = import_module(models_module_name)
      File "c:\users\bello\anaconda3\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\bello\Desktop\DESKTOP\EDX\mosque-around-you\mosque-around-you\mosquesinlocation\models.py", line 3, in <module>
        from cities_light.models import City, Region as State, Country
      File "C:\Users\bello\Envs\mosque-around-you\lib\site-packages\cities_light\models.py", line 83, in <module>
        from .abstract_models import (AbstractCountry, AbstractRegion,
      File "C:\Users\bello\Envs\mosque-around-you\lib\site-packages\cities_light\abstract_models.py", line 5, in <module>
        import autoslug
      File "C:\Users\bello\Envs\mosque-around-you\lib\site-packages\autoslug\__init__.py", line 11, in <module>
        from autoslug.fields import AutoSlugField
      File "C:\Users\bello\Envs\mosque-around-you\lib\site-packages\autoslug\fields.py", line 29, in <module>
        from autoslug.settings import slugify, autoslug_modeltranslation_enable
      File "C:\Users\bello\Envs\mosque-around-you\lib\site-packages\autoslug\settings.py", line 68, in <module>
        slugify = get_callable(slugify_function_path)
      File "C:\Users\bello\Envs\mosque-around-you\lib\site-packages\django\urls\utils.py", line 28, in get_callable
        mod = import_module(mod_name)
      File "c:\users\bello\anaconda3\lib\importlib\__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "C:\Users\bello\Envs\mosque-around-you\lib\site-packages\autoslug\utils.py", line 15, in <module>
        from django.db.models.fields import FieldDoesNotExist, DateField
    ImportError: cannot import name 'FieldDoesNotExist'

【问题讨论】:

  • FieldDoesNotExistdjango.core.exceptions 中。你想自己使用它吗?如果没有,您可能安装了与您使用的 Django 版本不兼容的库。
  • 如何找出导致问题的库?

标签: python django web backend


【解决方案1】:

您必须将 django-autoslug 从版本 &lt;= 1.9.7 更新到版本 1.9.8,因为 Django 3.1 删除了 FieldDoesNotExistdjango.db.models.fields 重新导入

作为documented

django.core.exceptions.FieldDoesNotExist 的兼容性导入 在 django.db.models.fields 中被移除。

【讨论】:

  • 我已经将 django-autoslug 升级到 1.9.8 版本,但问题仍然存在。感谢救援工作
  • 不应该是这种情况,因为这个错误在github.com/justinmayer/django-autoslug/blob/v1.9.8/autoslug/…中已经明确修复了你可能在不同的包中也有类似的错误,或者你没有正确更新环境
【解决方案2】:

我能够根据将 django-cities-light 包从版本 3.6.0 升级到 3.8.1 提出的提示解决问题

非常感谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-09
    • 2021-09-08
    • 1970-01-01
    • 2012-11-11
    • 1970-01-01
    • 1970-01-01
    • 2014-03-21
    相关资源
    最近更新 更多