公司强迫我们将 django 应用程序从 Linux 迁移到 Windows。我搜索了一下,发现 Helicon Zoo 是一个好主意,可以帮助我进行设置。
我已经按照描述安装了 zoo 部分,并尝试添加我的 django 应用程序,但它不起作用。为了确保我在应用程序中没有遇到复杂内容的问题,我创建了一个 mysite 演示页面,正如 django 教程中所述,所以现在我有了这个文件夹结构:
C:\inetpub\wwwroot\ZooPythonProject
我已经更改了 webconfig,所以它看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<heliconZoo>
<clear />
<application name="python.project">
<environmentVariables>
<add name="VIRTUAL_ENV" value="%APPL_PHYSICAL_PATH%\venv" />
<add name="PATH" value="%APPL_PHYSICAL_PATH%\venv\Scripts;% PATH%" />
<add name="PYTHONPATH" value="%APPL_PHYSICAL_PATH% \venv\lib\site-packages;%APPL_PHYSICAL_PATH%\venv\lib;%APPL_PHYSICAL_PATH%;% APPL_PHYSICAL_PATH%\mysite" />
<!-- <add name="WSGI_APP" value="welcome.application" /> -->
<add name="CONSOLE_URL" value="console" />
<add name="DEPLOY_FILE" value="deploy.py" />
<add name="ERROR_LOG_DIR" value="log" />
<!-- generic wsgi app -->
<!-- django project --> <add name="DJANGO_SETTINGS_MODULE" value="mysite.settings" />
我知道设置文件被视为好像我更改了设置文件的名称我收到一条不同的错误消息,指出找不到该文件。
我启动 IIS 并检查我的日志文件,它给了我这个错误消息:
No handlers could be found for logger "django.request"
Traceback (most recent call last):
File "C:\Zoo\Workers\python\zoofcgi.py", line 1069, in <module>
run_django_app(options.django_settings_module, options.django_root)
File "C:\Zoo\Workers\python\zoofcgi.py", line 999, in run_django_app
FCGIServer(WSGIHandler(), app_root=django_root).run()
File "C:\Zoo\Workers\python\zoofcgi.py", line 776, in run
conn.run()
File "C:\Zoo\Workers\python\zoofcgi.py", line 569, in run
self.process_input()
File "C:\Zoo\Workers\python\zoofcgi.py", line 600, in process_input
self._do_stdin(rec)
File "C:\Zoo\Workers\python\zoofcgi.py", line 724, in _do_stdin
self._start_request(req)
File "C:\Zoo\Workers\python\zoofcgi.py", line 697, in _start_request
req.run()
File "C:\Zoo\Workers\python\zoofcgi.py", line 515, in run
protocolStatus, appStatus = self.server.handler(self)
File "C:\Zoo\Workers\python\zoofcgi.py", line 862, in handler
result = self.application(environ, start_response)
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\core\handlers\wsgi.py", line 189, in __call__
response = self.get_response(request)
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\core\handlers\base.py", line 218, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\core\handlers\base.py", line 261, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\views\debug.py", line 97, in technical_500_response
html = reporter.get_traceback_html()
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\views\debug.py", line 384, in get_traceback_html
return t.render(c)
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\template\base.py", line 209, in render
return self._render(context)
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\template\base.py", line 201, in _render
return self.nodelist.render(context)
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\template\base.py", line 903, in render
bit = self.render_node(node, context)
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\template\debug.py", line 79, in render_node
return node.render(context)
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\template\debug.py", line 89, in render
output = self.filter_expression.resolve(context)
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\template\base.py", line 674, in resolve
new_obj = func(obj, *arg_vals)
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\template\defaultfilters.py", line 774, in date
return format(value, arg)
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\utils\dateformat.py", line 345, in format
return df.format(format_string)
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\utils\dateformat.py", line 37, in format
pieces.append(force_text(getattr(self, piece)()))
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\utils\dateformat.py", line 270, in r
return self.format('D, j M Y H:i:s O')
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\utils\dateformat.py", line 37, in format
pieces.append(force_text(getattr(self, piece)()))
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\utils\encoding.py", line 92, in force_text
s = six.text_type(s)
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\utils\functional.py", line 141, in __text_cast
return func(*self.__args, **self.__kw)
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\utils\translation\__init__.py", line 84, in ugettext
return _trans.ugettext(message)
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\utils\translation\trans_real.py", line 323, in ugettext
return do_translate(message, 'ugettext')
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\utils\translation\trans_real.py", line 300, in do_translate
_default = _default or translation(settings.LANGUAGE_CODE)
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\utils\translation\trans_real.py", line 206, in translation
_translations[language] = DjangoTranslation(language)
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\utils\translation\trans_real.py", line 116, in __init__
self._add_installed_apps_translations()
File "C:\inetpub\wwwroot\ZooPythonProject\venv\lib\site-packages\django\utils\translation\trans_real.py", line 164, in _add_installed_apps_translations
"The translation infrastructure cannot be initialized before the "
django.core.exceptions.AppRegistryNotReady: The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don't make non-lazy gettext calls at import time.
这些是我的设置:
"""
Django settings for mysite project.
Generated by 'django-admin startproject' using Django 1.8.3.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
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.8/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'u%196@-06u3np&!y91km4hp@ufn+80%op1$o5hrqp#c!$y-n-h'
# 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_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = r'C:\inetpub\wwwroot\ZooPythonProject\mysite.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 = 'mysite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/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.8/howto/static-files/
STATIC_URL = '/static/'
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'standard': {
'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
},
},
'handlers': {
'default': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'filename': 'logs/mylog.log',
'maxBytes': 1024*1024*5, # 5 MB
'backupCount': 5,
'formatter':'standard',
},
'request_handler': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'filename': 'logs/django_request.log',
'maxBytes': 1024*1024*5, # 5 MB
'backupCount': 5,
'formatter':'standard',
},
},
'loggers': {
'': {
'handlers': ['default'],
'level': 'DEBUG',
'propagate': True
},
'django.request': {
'handlers': ['request_handler'],
'level': 'DEBUG',
'propagate': False
},
}
}
有人知道如何设置这个简单的 django 页面吗?如果我在没有 IIS 和 Zoo 的情况下运行它并且只执行 manage.py 运行服务器,它就可以工作,但这不是我们的生产服务器的选项。
谢谢你的帮助!
前夕