导入模块时出错 - ImproperlyConfigured:WSGI应用程序

时间:2017-12-30 22:11:50

标签: python django

我最初使用名为auth的应用创建了一个Django项目,但遇到了一些错误并将其更改为authentication。后来,当我试图runserver时,我发现因为错误而无法发现:

django.core.exceptions.ImproperlyConfigured: WSGI application 'coolwebsite.wsgi.application' could not be loaded; Error importing module: 'No module named 'django.contrib.authentication''

所以我在网上看了一下,事实证明我不应该命名与Django应用程序结构相同的应用程序。我将authentication更改为oauth,我仍然收到同样的错误:

django.core.exceptions.ImproperlyConfigured: WSGI application 'coolwebsite.wsgi.application' could not be loaded; Error importing module: 'No module named 'django.contrib.oauth''

我将应用名称更改为birds,但仍然会出现同样的错误。我不明白为什么我仍然收到这个错误。

完整错误是:

Traceback (most recent call last):
  File "C:\python3.6.3\lib\site-packages\django\utils\autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "C:\python3.6.3\lib\site-packages\django\core\management\commands\runserver.py", line 147, in inner_run
    handler = self.get_handler(*args, **options)
  File "C:\python3.6.3\lib\site-packages\django\contrib\staticfiles\management\commands\runserver.py", line 28, in get_handler
    handler = super(Command, self).get_handler(*args, **options)
  File "C:\python3.6.3\lib\site-packages\django\core\management\commands\runserver.py", line 68, in get_handler
    return get_internal_wsgi_application()
  File "C:\python3.6.3\lib\site-packages\django\core\servers\basehttp.py", line 57, in get_internal_wsgi_application
    sys.exc_info()[2])
  File "C:\python3.6.3\lib\site-packages\django\utils\six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "C:\python3.6.3\lib\site-packages\django\core\servers\basehttp.py", line 47, in get_internal_wsgi_application
    return import_string(app_path)
  File "C:\python3.6.3\lib\site-packages\django\utils\module_loading.py", line 20, in import_string
    module = import_module(module_path)
  File "C:\python3.6.3\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\xxx\PycharmProjects\coolwebsite\coolwebsite\wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "C:\python3.6.3\lib\site-packages\django\core\wsgi.py", line 14, in get_wsgi_application
    return WSGIHandler()
  File "C:\python3.6.3\lib\site-packages\django\core\handlers\wsgi.py", line 151, in __init__
    self.load_middleware()
  File "C:\python3.6.3\lib\site-packages\django\core\handlers\base.py", line 80, in load_middleware
    middleware = import_string(middleware_path)
  File "C:\python3.6.3\lib\site-packages\django\utils\module_loading.py", line 20, in import_string
    module = import_module(module_path)
  File "C:\python3.6.3\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 941, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
django.core.exceptions.ImproperlyConfigured: WSGI application 'coolwebsite.wsgi.application' could not be loaded; Error importing module: 'No module named 'django.contrib.oauth''

我已安装的应用:

INSTALLED_APPS = [
    ###APPS###
    'oauth.apps.OauthConfig',

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles'
]

为什么我收到此错误?

1 个答案:

答案 0 :(得分:1)

因为这些模块都不存在。该应用程序名为“django.contrib.auth”。