简体   繁体   English

在Apache mod_python上部署Django应用

[英]Deploying django app on Apache mod_python

I've finished making a site in django called 'kazbah', and I'm trying to deploy. 我已经完成了在django中创建的名为“ kazbah”的网站,并且我正尝试进行部署。

All the code for the kazbah site is in /home/git/DjangoProjects/kazbah and my httpd.conf looks like: kazbah网站的所有代码都在/ home / git / DjangoProjects / kazbah中,而我的httpd.conf看起来像:

<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 ImportError:无法导入设置“ kazbah.settings”(在sys.path上吗?是否存在语法错误?):没有名为kazbah.settings的模块

Any idea why this noob is failing? 知道为什么这个菜鸟失败了吗?

For a project resting under /var/www/bbb (called, "bbb"), I have the following set in the configuration file: 对于位于/var/www/bbb (称为“ bbb”)下的项目,我在配置文件中进行了以下设置:

<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>

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. 尽管看起来不错,但Django(实际上是python)正在寻找一个我想要的文件夹。 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. 没有看到您的实际文件夹设置,很难确切知道。 :) :)

Louis, your configuration looks exactly like ones I used before I switched to mod_wsgi, so there must be something else wrong. 路易斯,您的配置与我切换到mod_wsgi之前使用的配置完全相同,因此肯定还有其他问题。 Maybe you are missing an __init__.py file in /home/git/DjangoProjects/kazbah? 也许您在/ home / git / DjangoProjects / kazbah中缺少__init__.py文件?

I'm pretty sure you can do the sys.path thing - it's in the django documentation. 我很确定您可以做sys.path事情-在django文档中。

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/ 当我尝试其他教程时,我可能会翻阅django doc http://docs.djangoproject.com/en/dev/howto/deployment/modpython/ (我认为这有点过时了) -http://www.jeffbaier .com / 2007/07/26 / installing-django-on-an-ubuntu-linux-server /

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. 如果存在任何错误,以这种方式进行操作将为您提供更好的错误消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM