安装环境和软件版本:win7 64位。python 2.7.6 32位,django 1.4.9,apache 2.2,mod_wsgi-win32-ap22py27-3.3.so。mod_wsgi下载地址
将下载的mod_wsgi.so拷贝到 apache 的modules目录。
修改apache 配置文件http.conf(参考django文档)
WSGIPythonHome D:/python27 Alias /static/ D:/sampleinfo_learn/staticRoot/ Alias /media/ D:/sampleinfo_learn/media/ <Directory D:/sampleinfo_learn/media> Order deny,allow Allow from all </Directory> <Directory D:/sampleinfo_learn/staticRoot> Order deny,allow Allow from all </Directory> WSGIScriptAlias / D:/sampleinfo_learn/mysite/wsgi.py WSGIPythonPath D:/sampleinfo_learn <Directory D:/sampleinfo_learn/mysite> <Files wsgi.py> Order deny,allow Allow from all </Files> </Directory> LoadModule wsgi_module modules/mod_wsgi.so
收集静态文件,改由apache提供服务。
python manage.py collectstatic
django数据库和路径设置,由于用户数很少,仍采用sqlite3数据库。
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.split(__file__)[0]+'/../data.sqlite' } } DEBUG=False ALLOWED_HOSTS=['*'] # Absolute path to the directory that holds media. # Example: "/home/media/media.lawrence.com/" MEDIA_ROOT = os.path.split(__file__)[0]+"/../media/" # URL that handles the media served from MEDIA_ROOT. # Example: "http://media.lawrence.com" MEDIA_URL = '/media/' STATIC_ROOT = os.path.split(__file__)[0]+"/../staticRoot/" # URL prefix for static files. # Example: "http://example.com/static/", "http://static.example.com/" STATIC_URL = '/static/' LOCALE_PATHS=( os.path.split(__file__)[0]+"/../conf/locale", ) # Additional locations of static files STATICFILES_DIRS = ( os.path.split(__file__)[0]+"/../static/", # Put strings here, like "/home/html/static" or "C:/www/django1/static". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. ) # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a # trailing slash. # Examples: "http://foo.com/media/", "/media/". ADMIN_MEDIA_PREFIX = '/media/'
wsgi.py文件为django 建立工程时生成的,不需改变
import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") from django.core.wsgi import get_wsgi_application application = get_wsgi_application()