简体   繁体   English

Windows Server VM上的Django Hello World Web应用

[英]Django Hello World web app on a Windows Server VM

Good Evening, I am trying to setup hello world app on azure cloud. 晚上好,我正在尝试在Azure云上设置hello world应用程序。 I am following the tutorial Django hello world web app on windows server vm 我正在Windows Server vm上关注Django Hello World Web应用程序教程

After doing all the set up when I navigate to the http://localhost/ 完成所有设置后,当我导航到http:// localhost /时

I get following error 我收到以下错误

Error occurred while reading WSGI handler: Traceback (most recent call last): File "c:\\users\\compUser\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\wfastcgi.py", line 791, in main env, handler = read_wsgi_handler(response.physical_path) File "c:\\users\\compUser\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\wfastcgi.py", line 633, in read_wsgi_handler handler = get_wsgi_handler(os.getenv("WSGI_HANDLER")) File "c:\\users\\compUser\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\wfastcgi.py", line 605, in get_wsgi_handler handler = handler() File "c:\\users\\compUser\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\django\\core\\handlers\\wsgi.py", line 151, in init self.load_middleware() File "c:\\users\\compUser\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\django\\core\\handlers\\base.py", line 81, in load_middleware middleware = import_string(middleware_path) File "c:\\users\\compUser\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\django\\ut\u003c/i> 读取WSGI处理程序时发生错误:追溯(最近一次调用最近):文件“ c:\\ users \\ compUser \\ appdata \\ local \\ programs \\ python \\ python36 \\ lib \\ site-packages \\ wfastcgi.py”,主行中的第791行env,处理程序= read_wsgi_handler(response.physical_path)文件“ c:\\ users \\ compUser \\ appdata \\ local \\ programs \\ python \\ python36 \\ lib \\ site-packages \\ wfastcgi.py”,行633,在read_wsgi_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()文件中c:\\ users \\ compUser \\ appdata \\ local \\ programs \\ python \\ python36 \\ lib \\ site-packages \\ django \\ core \\ handlers \\ wsgi.py“,第151行, init self.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 \\应用程序数据\\本地\\程序\\ python的\\ python36 \\ LIB \\站点包\\ Django的\\ UT ils\\module_loading.py", line 20, in import_string module = import_module(module_path) File "c:\\users\\compUser\\appdata\\local\\programs\\python\\python36\\lib\\importlib__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 994, in _gcd_import File "", line 971, in _find_and_load File "", line 955, in _find_and_load_unlocked File "", line 665, in _load_unlocked File "", line 678, in exec_module File "", line 219, in _call_with_frames_removed File "c:\\users\\compUser\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\django\\contrib\\auth\\middleware.py", line 4, in from django.contrib.auth.backends import RemoteUserBackend File "c:\\users\\compUser\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\django\\contrib\\auth\\backends.py", line 4, in from django.contrib.auth.models import Permission File "c:\\users\\compUser\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\django\\contrib\\auth\\models.py", line 4, in from django.co ils \\ module_loading.py”,第20行,在import_string模块= import_module(module_path)文件“ c:\\ users \\ compUser \\ appdata \\ local \\ programs \\ python \\ python36 \\ lib \\ importlib__init __。py”,第126行,在import_module返回中_bootstrap._gcd_import(name [level:],程序包,级别)文件“”,第994行,在_gcd_import文件“”,第971行,在_find_and_load文件“”,第955行,在_find_and_load_unlocked文件“”,在_load_unlocked,行665 exec_module中的文件“”,第678行,_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.co ntrib.auth.base_user import AbstractBaseUser, BaseUserManager File "c:\\users\\compUser\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\django\\contrib\\auth\\base_user.py", line 52, in class AbstractBaseUser(models.Model): File "c:\\users\\compUser\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\django\\db\\models\\base.py", line 110, in new app_config = apps.get_containing_app_config(module) File "c:\\users\\compUser\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\django\\apps\\registry.py", line 247, in get_containing_app_config self.check_apps_ready() File "c:\\users\\compUser\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\django\\apps\\registry.py", line 125, in check_apps_ready raise AppRegistryNotReady("Apps aren't loaded yet.") django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. ntrib.auth.base_user导入AbstractBaseUser,BaseUserManager文件“ 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行,在新的 app_config = apps.get_tained_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:应用尚未加载。 StdOut: StdErr: StdOut:StdErr:

I saw in some post, people suggested to add django.setup() like for standalone apps, that did not work or I put that in wrong spot. 我在一些帖子中看到,人们建议像为独立应用程序那样添加django.setup(),该命令无法正常工作,或者我将其放在错误的位置。 I tried to run python manage.py runserver and it ran without error. 我试图运行python manage.py runserver,它运行无误。

Following is my web.config file 以下是我的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>

This is my settings.py 这是我的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/'

In web.config , replace: web.config ,替换为:

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

with: 有:

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

refer to django source code . 参考django源代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM