简体   繁体   中英

Django Hello World web app on a Windows Server VM

Good Evening, I am trying to setup hello world app on azure cloud. I am following the tutorial Django hello world web app on windows server vm

After doing all the set up when I navigate to the 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> 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 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. 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. I tried to run python manage.py runserver and it ran without error.

Following is my web.config file

<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

    """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:

<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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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