Python manage.py runserver 不适用于项目 (Django)



所以我做了自己的项目,它适用于python manage.py runserver但是当我尝试一个新项目时,这是一个挑战项目,挑战是改进django应用程序。我使用 Python 3.8.1(64 位(,当我在 Admin Powershell 上编写python manage.py runserver时,它给了我这个错误:

Traceback (most recent call last):
File "C:UsersthatpAppDataLocalProgramsPythonPython38-32libthreading.py", line 932, in _bootstrap_inner
self.run()
File "C:UsersthatpAppDataLocalProgramsPythonPython38-32libthreading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:UsersthatpAppDataLocalProgramsPythonPython38-32libsite-packagesdjangoutilsautoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:UsersthatpAppDataLocalProgramsPythonPython38-32libsite-packagesdjangocoremanagementcommandsrunserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:UsersthatpAppDataLocalProgramsPythonPython38-32libsite-packagesdjangoutilsautoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "C:UsersthatpAppDataLocalProgramsPythonPython38-32libsite-packagesdjangocoremanagement__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "C:UsersthatpAppDataLocalProgramsPythonPython38-32libsite-packagesdjangoutilsautoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:UsersthatpAppDataLocalProgramsPythonPython38-32libsite-packagesdjango__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:UsersthatpAppDataLocalProgramsPythonPython38-32libsite-packagesdjangoappsregistry.py", line 114, in populate
app_config.import_models()
File "C:UsersthatpAppDataLocalProgramsPythonPython38-32libsite-packagesdjangoappsconfig.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "C:UsersthatpAppDataLocalProgramsPythonPython38-32libimportlib__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:djangoProjectsdjango-challenge-masterappmailermodels.py", line 6, in <module>
from django.utils.encoding import python_2_unicode_compatible
ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding' (C:UsersthatpAppDataLocalProgramsPythonPython38-32libsite-packagesdjangoutilsencoding.py)

所以如果有人能帮助我,那就太棒了。

错误出在您的模型中,请参见下文:

from django.utils.encoding import python_2_unicode_compatible
ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding' (C:UsersthatpAppDataLocalProgramsPythonPython38-32libsite-packagesdjangoutilsencoding.py

它只适用于 Django>=1.5,见这里:https://stackoverflow.com/a/20741848/9710734

最新更新