在 Apache mod_python 上部署 django 应用程序

发布于 2024-07-13 12:49:21 字数 562 浏览 8 评论 0原文

我已经在 django 中制作了一个名为“kazbah”的网站,并且正在尝试部署。

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> 

但我收到以下错误:

ImportError: Could not import settings 'kazbah.settings' (Is it on sys.path ?它有语法错误吗?):没有名为 kazbah.settings 的模块

知道为什么这个菜鸟失败了吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

櫻之舞 2024-07-20 12:49:21

对于位于 /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>

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>
煮酒 2024-07-20 12:49:21

我已经见过几次了。 每次都是因为我错误地设置了这一行:

SetEnv DJANGO_SETTINGS_MODULE kazbah.settings

尽管它看起来是正确的,但 Django(实际上是 python)正在查找与我想要的文件夹不同的文件夹。 尝试调整它,将其更改为:

SetEnv DJANGO_SETTINGS_MODULE settings

另外,您可以在此处调整:

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

可能您需要将其设置为:

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

或类似的内容。 如果没有看到实际的文件夹设置,就很难准确地知道。 :)

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

未央 2024-07-20 12:49:21

路易斯,你的配置看起来和我切换到 mod_wsgi 之前使用的配置一模一样,所以肯定还有其他问题。 也许您在 /home/git/DjangoProjects/kazbah 中缺少 __init__.py 文件?

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?

吲‖鸣 2024-07-20 12:49:21

我很确定你可以做 sys.path 的事情 - 它在 django 文档中。

我可能会查看 django 文档 http://docs.djangoproject.com/ en/dev/howto/deployment/modpython/ 因为我正在尝试另一个教程(我认为这有点过时) - http://www.jeffbaier.com/2007/07/26/installing-django-on-an-ubuntu-linux -服务器/

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/

海之角 2024-07-20 12:49:21

好的,也许您的设置文件中有语法错误。

试试这个:

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

如果有任何错误,这样做会给你一个更好的错误消息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文