Deploying django app on Apache mod_python

2019-03-22 07:36发布

I've finished making a site in django called 'kazbah', and I'm trying to deploy.

All the code for the kazbah site is in /home/git/DjangoProjects/kazbah and my httpd.conf looks like:

<Location "/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE kazbah.settings
    PythonDebug On
    PythonPath "['/home/git/DjangoProjects'] + sys.path"
</Location> 

I get the following error though:

ImportError: Could not import settings 'kazbah.settings' (Is it on sys.path? Does it have syntax errors?): No module named kazbah.settings

Any idea why this noob is failing?

5条回答
做个烂人
2楼-- · 2019-03-22 08:13

For a project resting under /var/www/bbb (called, "bbb"), I have the following set in the configuration file:

<Location "/">
        SetHandler python-program
        PythonHandler django.core.handlers.modpython
        SetEnv DJANGO_SETTINGS_MODULE bbb.settings
        PythonPath "['/var/www/', '/var/www/bbb/'] + sys.path"
        PythonDebug On
</Location>
查看更多
【Aperson】
3楼-- · 2019-03-22 08:17

Louis, your configuration looks exactly like ones I used before I switched to mod_wsgi, so there must be something else wrong. Maybe you are missing an __init__.py file in /home/git/DjangoProjects/kazbah?

查看更多
该账号已被封号
4楼-- · 2019-03-22 08:23

I'm pretty sure you can do the sys.path thing - it's in the django documentation.

I might go over the django doc http://docs.djangoproject.com/en/dev/howto/deployment/modpython/ as I was trying another tutorial(which is a bit outdated I think) - http://www.jeffbaier.com/2007/07/26/installing-django-on-an-ubuntu-linux-server/

查看更多
孤傲高冷的网名
5楼-- · 2019-03-22 08:32

I've seen this a few times. Every time, it's been because I incorrectly set this line:

SetEnv DJANGO_SETTINGS_MODULE kazbah.settings

Even though it looked right, Django (actually python) was looking one folder off from the one I intended. Try tweaking it, changing it to:

SetEnv DJANGO_SETTINGS_MODULE settings

Also, you can tweak here:

PythonPath "['/home/git/DjangoProjects'] + sys.path"

It might be that you need to set it to:

PythonPath "['/home/git/DjangoProjects/kazbah'] + sys.path"

or something similar. Without seeing your actual folder setup, it's hard to know exactly. :)

查看更多
戒情不戒烟
6楼-- · 2019-03-22 08:38

Ok, maybe you have a syntax error in your settings file.

Try this:

$ cd /home/git/DjangoProjects/kazbah
$ python
>>> import settings

Doing it this way will give you a much better error message if there are any errors.

查看更多
登录 后发表回答