首页 > 解决方案 > 我的开发服务器运行后报这个错误

问题描述

我的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'

标签: pythondjangowebbackend

解决方案


您必须django-autoslug从一个版本更新<= 1.9.7到另一个版本,1.9.8因为 Django3.1删除了FieldDoesNotExist重新导入django.db.models.fields

记录的

删除了 django.db.models.fields 中 django.core.exceptions.FieldDoesNotExist 的兼容性导入。


推荐阅读