Deploying django app on Apache mod_python

落爺英雄遲暮 提交于 2019-12-04 14:45:40

问题


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?


回答1:


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>



回答2:


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. :)




回答3:


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:


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:


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.



来源:https://stackoverflow.com/questions/500214/deploying-django-app-on-apache-mod-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!