今天做好了第二个django项目,但在部署时出了一点小问题,在此记录一下。

1、mod_wsgi 3.4已经支持了部署多个项目,只需在httpd.conf中进行如下配置:

WSGIScriptAlias /website1 "D:\website1\django.wsgi"
<Directory "D:\website1\django.wsgi">
    Options ExecCGI
    Order deny,allow
    Allow from all
</Directory>

WSGIScriptAlias /website2 "D:\website2\django.wsgi"
<Directory "D:\website2\django.wsgi">
    Options ExecCGI
    Order deny,allow
    Allow from all
</Directory>


2、urls.py需要修改一下,如下:

from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'cloudweb.views.home', name='home'),
    # url(r'^cloudweb/', include('cloudweb.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    # url(r'^admin/', include(admin.site.urls)),
    
    #url(r'^initos/$', 'cloudapp.views.initos'),
    url(r'^$', 'cloudapp.views.publish'),
    url(r'^submit/$', 'cloudapp.views.publish_submit'),
)

原来按照官方文档是这样设置的:

httpd.conf:
WSGIScriptAlias / "D:\website1\django.wsgi"
urls.py:
url('^website1/submit/$', 'cloudapp.views.publis_submit'),


3、如果碰到如下错误:

[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28] mod_wsgi (pid=7976): Exception occurred processing WSGI script 'D:/website1/django.wsgi'.
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28] Traceback (most recent call last):
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]   File "C:\\Python26\\lib\\site-packages\\django\\core\\handlers\\wsgi.py", line 236, in __call__
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]     self.load_middleware()
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]   File "C:\\Python26\\lib\\site-packages\\django\\core\\handlers\\base.py", line 51, in load_middleware
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]     mod = import_module(mw_module)
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]   File "C:\\Python26\\lib\\site-packages\\django\\utils\\importlib.py", line 35, in import_module
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]     __import__(name)
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]   File "C:\\Python26\\lib\\site-packages\\django\\contrib\\auth\\middleware.py", line 3, in <module>
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]     from django.contrib.auth.backends import RemoteUserBackend
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]   File "C:\\Python26\\lib\\site-packages\\django\\contrib\\auth\\backends.py", line 3, in <module>
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]     from django.contrib.auth.models import Permission
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]   File "C:\\Python26\\lib\\site-packages\\django\\contrib\\auth\\models.py", line 8, in <module>
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]     from django.db import models
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]   File "C:\\Python26\\lib\\site-packages\\django\\db\\models\\__init__.py", line 12, in <module>
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]     from django.db.models.fields.files import FileField, ImageField
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]   File "C:\\Python26\\lib\\site-packages\\django\\db\\models\\fields\\files.py", line 7, in <module>
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]     from django.core.files.storage import default_storage
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]   File "C:\\Python26\\lib\\site-packages\\django\\core\\files\\storage.py", line 12, in <module>
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]     from django.core.files import locks, File
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]   File "C:\\Python26\\lib\\site-packages\\django\\core\\files\\locks.py", line 24, in <module>
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]     import pywintypes
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]   File "C:\\Python26\\lib\\site-packages\\win32\\lib\\pywintypes.py", line 124, in <module>
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]     __import_pywin32_system_module__("pywintypes", globals())
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]   File "C:\\Python26\\lib\\site-packages\\win32\\lib\\pywintypes.py", line 114, in __import_pywin32_system_module__
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28]     assert sys.modules[modname] is old_mod
[Wed Sep 04 18:03:45 2013] [error] [client 10.16.16.28] AssertionError

找到C:\Python26\lib\site-packages\win32\lib\pywintypes.py文件的114行,修改如下:

 

if sys.version_info < (3,0):
        pass
##        assert sys.modules[modname] is old_mod
##        assert mod is old_mod
    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__)

 

 

现在两个站点均可访问:)

posted on 2013-09-04 18:32  一个人的天空@  阅读(4973)  评论(0编辑  收藏  举报