windows环境下部署django mod_wsgi apache

安装环境和软件版本: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()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值