【问题标题】:Django Hello World web app on a Windows Server VMWindows Server VM 上的 Django Hello World Web 应用程序
【发布时间】:2018-03-23 19:45:06
【问题描述】:

晚上好, 我正在尝试在 azure 云上设置 hello world 应用程序。我正在关注教程Django hello world web app on windows server vm

完成所有设置后,当我导航到http://localhost/

我收到以下错误

读取 WSGI 处理程序时发生错误:Traceback(最近一次调用最后一次): 文件“c:\users\compUser\appdata\local\programs\python\python36\lib\site-packages\wfastcgi.py”,第 791 行,在主环境中,handler = read_wsgi_handler(response.physical_path) 文件“c:\users\compUser\appdata\local\programs\python\python36\lib\site-packages\wfastcgi.py”,第 633 行,在 read_wsgi_handler handler = get_wsgi_handler(os.getenv("WSGI_HANDLER")) 文件“c:\users\compUser\appdata\local\programs\python\python36\lib\site-packages\wfastcgi.py”,第 605 行,在 get_wsgi_handler handler = handler() init 中的文件“c:\users\compUser\appdata\local\programs\python\python36\lib\site-packages\django\core\handlers\wsgi.py”,第 151 行。 load_middleware() 文件“c:\users\compUser\appdata\local\programs\python\python36\lib\site-packages\django\core\handlers\base.py”,第 81 行,在 load_middleware 中间件 = import_string(middleware_path) 文件“c:\users\compUser\appdata\local\programs\python\python36\lib\site-packages\django\utils\module_loading.py”,第 20 行,在 import_string module = import_module(module_path) 文件“c:\users\compUser\appdata\local\programs\python\python36\lib\importlib__init__.py”,第 126 行,在 import_module return _bootstrap._gcd_import(name[level:], package, level) _gcd_import 中的文件“”,第 994 行 _find_and_load 中的文件“”,第 971 行 文件“”,第 955 行,在 _find_and_load_unlocked _load_unlocked 中的文件“”,第 665 行 文件“”,第 678 行,在 exec_module 中 _call_with_frames_removed 中的文件“”,第 219 行 文件“c:\users\compUser\appdata\local\programs\python\python36\lib\site-packages\django\contrib\auth\middleware.py”,第 4 行,从 django.contrib.auth.backends 导入 RemoteUserBackend 文件“c:\users\compUser\appdata\local\programs\python\python36\lib\site-packages\django\contrib\auth\backends.py”,第 4 行,来自 django.contrib.auth.models 导入权限 文件“c:\users\compUser\appdata\local\programs\python\python36\lib\site-packages\django\contrib\auth\models.py”,第 4 行,从 django.contrib.auth.base_user 导入 AbstractBaseUser , 基本用户管理器 文件“c:\users\compUser\appdata\local\programs\python\python36\lib\site-packages\django\contrib\auth\base_user.py”,第 52 行,在 AbstractBaseUser(models.Model) 类中: 文件“c:\users\compUser\appdata\local\programs\python\python36\lib\site-packages\django\db\models\base.py”,第 110 行,在 new app_config = apps.get_ contains_app_config(模块) 文件“c:\users\compUser\appdata\local\programs\python\python36\lib\site-packages\django\apps\registry.py”,第 247 行,在 get_ contains_app_config self.check_apps_ready() 文件“c:\users\compUser\appdata\local\programs\python\python36\lib\site-packages\django\apps\registry.py”,第 125 行,在 check_apps_ready 中引发 AppRegistryNotReady(“应用程序尚未加载。 ") django.core.exceptions.AppRegistryNotReady:应用程序尚未加载。标准输出:标准错误:

我在一些帖子中看到,人们建议添加 django.setup() 之类的独立应用程序,但它不起作用,或者我把它放在了错误的位置。我尝试运行 python manage.py runserver 并且运行没有错误。

以下是我的 web.config 文件

<configuration>
<appSettings>
    <add key="WSGI_HANDLER" value="django.core.handlers.wsgi.WSGIHandler()" />
    <add key="PYTHONPATH" value="C:\inetpub\wwwroot\resumeApp" />
    <add key="DJANGO_SETTINGS_MODULE" value="resumeApp.settings" />

    <!-- optional settings -->
    <add key="WSGI_LOG" value="C:\inetpub\wwwroot\resumeApp\Logs\resumeApp.log" />
</appSettings>
<system.webServer>
    <handlers>
        <add name="Python FastCGI" 
            path="*" 
            verb="*" 
            modules="FastCgiModule" 
            scriptProcessor="c:\users\compUser\appdata\local\programs\python\python36\python.exe|c:\users\compUser\appdata\local\programs\python\python36\lib\site-packages\wfastcgi.py" 
            resourceType="Unspecified" />
    </handlers>
</system.webServer>

这是我的 settings.py

    """enter code hereDjango settings for resumeApp project.
Generated by 'django-admin startproject' using Django 1.11.6.

For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '<removed>'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

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

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'resumeApp.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'resumeApp.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/

STATIC_URL = '/static/'

【问题讨论】:

  • 似乎没有设置 DJANGO_SETTINGS_MODULE。无论正在运行您的 wsgi 应用程序,例如WFastCGI 将有一个配置文件,需要将您的项目目录添加到 PYTHONPATH 环境变量并设置 DJANGO_SETTINGS_MODULE 环境变量。
  • 添加了 config 和 setting.py 文件。本教程未涉及这些文件。只是更改了 web.config 值以匹配我的设置。

标签: python django azure python-3.6


【解决方案1】:

web.config 中,替换:

<add key="WSGI_HANDLER" value="django.core.handlers.wsgi.WSGIHandler()" />

与:

<add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" />

参考django source code

【讨论】:

  • 谢谢谢谢谢谢。现在我得到了一个不同的错误。我会努力的:)
  • 只是好奇,你是怎么想出来的?
猜你喜欢
  • 2018-02-02
  • 2014-05-17
  • 2017-04-20
  • 1970-01-01
  • 2021-12-07
  • 2017-11-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多