Setup Djangoproject on windows 2012 with Helicon Zoo

185 Views Asked by At

We were forced by the company to move our django app from Linux to Windows. I googled and there I found Helicon Zoo is meant to be a good idea to help me setting this up.

I have installed the zoo part as it was described and tried to add my django application which did not work. To be sure I am not having problems with complex stuff in the application I have created a mysite demopage as it was described in the django tutorial so now I have got this folder structure:

C:\inetpub\wwwroot\ZooPythonProject

I have changed the webconfig so it looks like this:

<?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" />

I know that the setting file is taken as if I change the name of the setting file I get a different error message saying that the file cannot be found.

I start IIS and check my logfile it is giving me this error message:

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.

These are my settings:

"""
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
        },
    }
}

Does anybody have an idea how to setup this simple django page? It works if I run it without IIS and Zoo and just do a manage.py runserver, but this is not an option for our production server.

Thanks for your help!

Eve

1

There are 1 best solutions below

0
On

The problem may (or may not) come from "zoofcgi.py" script. Sorry for inconvenience anyway. Could you please try a preview release of Zoo v.4 instead: https://github.com/helicontech/zoo/releases It uses different workers for Python application, so your issue may be resolved. Sorry, no documentation yet, but if you already familiar with MS WebPI, then it should be easy to use Zoo for you. After installing it, please, open Applications -> Templates and install "Python sample project". Open it in the browser and there you should find instructions how to put your existing Django project on it.

Sorry, it is still an early beta and applications outside 'Templates' section have not even been tested yet. As I work alone on this project I can't promise fast results, but at least in is open source now and underlying module code that runs applications has not changed significantly, so it is safe to say that if it worked once, then it should work further at least not worse than the previous version.