Multiple django sites on Apache / Windows / mod
I have two django sites that use the same database and share some of the code. The main parent site is an extranet for staff and contractors, while the second site exposes some of the data to a few of our partners.
I have managed to set up sites to work but found that if I launched Apache and went into the main site, then the partner site wouldn't work, returning an "Internal Server Error". If I restarted and went into the partner site, then the main site wouldn't work.
So I guess they are conflicting over resources.
The server log (see bottom) shows that it is a problem with the win32/lib/pywintypes.py module, line 114. Elsewhere, it's been suggested to comment out these lines (see below). So I've tried this and it works.
I don't really understand what is going on in the code and whether commenting it out is just going to cause me problems later. So the question is:
Is there something else going on that may be causing this? Is this fudge 'safe' to do?
# py2k and py3k differences:
# On py2k, after doing "imp.load_module('pywintypes')", sys.modules
# is unchanged - ie, sys.modules['pywintypes'] still refers to *this*
# .py module - but the module's __dict__ has *already* need updated
# with the new module's contents.
# However, on py3k, sys.modules *is* changed - sys.modules['pywintypes']
# will be changed to the new module object.
# SO: * on py2k don't need to update any globals.
# * on py3k we update our module dict with the new module's dict and
# copy its globals to ours.
old_mod = sys.modules[modname]
# Python can load the module
mod = imp.load_dynamic(modname, found)
# Check the sys.modules[] behaviour we describe above is true...
if sys.version_info < (3,0):
#The fudge bit !!!!!!!!!!!!!!!!!
#assert sys.modules[modname] is old_mod
#assert mod is old_mod
pass
else:
assert sys.modules[modname] is not old_mod
assert sys.modules[modname] is mod
# as above - re-reset to the *old* module object then update globs.
sys.modules[modname] = old_mod
globs.update(mod.__dict__)
Traceback
mod_wsgi (pid=7164): Exception occurred processing WSGI script 'E:/Programming/django_site/extranet_site/apache/django.wsgi'.
Traceback (most recent call last):
File "C:Python26libsite-packagesdjangocorehandlerswsgi.py", line 241, in __call__
response = self.get_response(request)
File "C:Python26libsite-packagesdjangocorehandlersbase.py", line 73, in get_response
response = middleware_method(request)
ile "C:Python26libsite-packagesdjangocontribsessionsmiddleware.py", line 10, in process_request
engine = import_module(settings.SESSION_ENGINE)
File "C:Python26libsite-packagesdjangoutilsimportlib.py", line 35, in import_module
__import__(name)
File "C:Python26libsite-packagesdjangocontribsessionsbackendsdb.py", line 2, in <module>
from django.contrib.sessions.models import Session
File "C:Python26libsite-packagesdjangocontribsessionsmodels.py", line 4, in <module>
from django.db import models
File "C:Python26libsite-packagesdjangodbmodels__init__.py", line 12, in <module>
from django.db.models.fields.files import FileField, ImageField
File "C:Python26libsite-packagesdjangodbmodelsfieldsfiles.py", line 8, in <module>
from django.core.files.storage import default_storage
File "C:Python26libsite-packagesdjangocorefilesstorage.py", line 7, in <module>
from django.core.files import locks, File
File "C:Python26libsite-packagesdjangocorefileslocks.py", line 25, in <module>
import pywintypes
File "C:Python26libsite-packageswin32libpywintypes.py", line 124, in <module>
__import_pywin32_system_module__("pywintypes", globals())
File "C:Python26libsite-packageswin32libpywintypes.py", line 114, in __import_pywin32_system_module__
assert sys.modules[modname is old_mod
AssertionError
安装pywin32#212解决了这个问题。
在删除pywin32并使用WSGIScriptAlias“/ aliasname”“c:/wamp/www/project/django.wsgi”之后,它对我有效。在httpd.config中也使用第一个参数的引号。
I ran into this on version 217, but I needed pywin32. Implementing fix from here https://stackoverflow.com/a/10928148/80516 seems to work.
Bug is reported, but not resolved:
https://sourceforge.net/tracker/?func=detail&aid=2905909&group_id=78018&atid=551954
Temporary solution is comment out two lines in win32/lib/pywintypes.py:
if sys.version_info < (3,0):
#next two lines are problematic!!!!!
#assert sys.modules[modname] is old_mod
#assert mod is old_mod
pass
else:
assert sys.modules[modname] is not old_mod
assert sys.modules[modname] is mod
# as above - re-reset to the *old* module object then update globs.
sys.modules[modname] = old_mod
globs.update(mod.__dict__)
链接地址: http://www.djcxy.com/p/6912.html
上一篇: HTML