How to use Django with Apache and mod_wsgi

来源:互联网 发布:深圳数据分析培训机构 编辑:程序博客网 时间:2024/05/18 02:21

edit httpd.conf

WSGIScriptAlias / /home/liuke/www/django/hello/apache/django.wsgi

add file

django.wsgi

import os
import sys

path = '/home/liuke/www/django/hello'
if path not in sys.path:
    sys.path.append(path)


#os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

官方网站上说是os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

这样会出错试了改为settings就可以

or
把path = '/home/liuke/www/django/hello'

改为path = '/home/liuke/www/django'

应该也可以吧

edit setting.py 开头加入

import sys
sys.path.append('/home/liuke/www/django/hello')
sys.path.append('/home/liuke/www/django/')

还有里面的path要是绝对path

sqlite3的数据文件为出现为readonly 的error,

要把数据文件单独放在一个dir里,然后

chown www-data. .

Aha, just stumbled across an article explaining this. Also Django have info on their NewbieMistakes page.

The solution is to make sure the directory containing the database file also has write access allowed to the process.

In my case, running this command fixed the problem:



原创粉丝点击