gpt4 book ai didi

python - 使用 Server.app 在 Mac OS X 10.9 上使用 Apache/mod_wsgi 部署 Django

转载 作者:太空宇宙 更新时间:2023-11-04 03:37:04 24 4
gpt4 key购买 nike

过去两天,我一直在尝试在运行 Server.app 的 Mac 10.9 上部署带有夹层的 Django 项目。我学到了很多,但到目前为止还没有运气。我已经阅读了几篇关于这个主题的文章:

https://apple.stackexchange.com/questions/151388/can-i-deploy-my-django-site-to-os-x-server Deploying Django on OS 10.9 Server

但是这些方法对我不起作用。

我一遍又一遍地浏览了 djangoproject 上的文档,但找不到解决方案。所以请耐心等待,我相信有解决方案。

我试图尽可能简单地做到这一点,甚至为了 Apple 的 Server.app 而忽略了 virtualenv我肯定在这里遗漏了一些东西......

这是我的设置:带有服务器应用程序 3 的 Mac OS X 10.9Python 2.7.9(通过 brew 安装) Django 1.6.10 Apache 2.2.26mod_wsgi 4.4.8 (通过 pip 表达版本)

项目代码本身位于/Users/_dev/MyProject/MyProject

配置文件:我将 wsgi.py 重命名为 MyProject.wsgi,它只是在 Server.app/Advanced 设置中列出了 MyProject,仅此而已。值得一提:Apple 的默认“hello world python 应用程序”也不起作用,我从未见过它,但认为它与 Apple 提供的默认启动画面不同。

/Library/Server/Web/Config/apache2/中的 httpd_wsgi2.conf

WSGIScriptAlias / /Users/_dev/MyProject/MyProject/MyProject.wsgi

<Directory /Users/_dev/MyProject/MyProject>
<Files MyProject.wsgi>
Order deny,allow
Allow from all
</Files>
</Directory>

com.apple.webapp.wsgi2.plist在/Library/Server/Web/Config/apache2/webapps/

/Users/_dev/MyProject/MyProject/MyProject.wsgi<?xml version="1.0" encoding="UTF-7"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>com.apple.webapp.wsgi2</string>
<key>displayName</key>
<string>Hot Club Setup at /</string>
<key>launchKeys</key>
<array/>
<key>proxies</key>
<dict/>
<key>installationIndicatorFilePath</key>
<string>/Users/_dev/MyProject/MyProject/MyProject.wsgi</string>
<key>includeFiles</key>
<array>
<string>/Library/Server/Web/Config/apache2/httpd_wsgi2.conf</string>
</array>
<key>requiredModuleNames</key>
<array>
<string>wsgi_module</string>
</array>
</dict>
</plist>

至少 Django 和 Mezzanine 在 Development Server 上运行良好python manage.py 运行服务器

mod_wsgi 似乎在/private/etc/apache2/httpd.conf : LoadModule wsgi_module libexec/apache2/mod_wsgi.somod_wsgi-express start-server 工作正常,至少对于 Malt whyskey splash 是这样。

但是当我输入 mod_wsgi-express start-server MyProject.wsgi我得到一个内部服务器错误/tmp/mod_wsgi-localhost:8000:507/error_log 的日志说:

ImportError: Could not import settings 'MyProject.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named MyProject.settings

比加

PYTHONPATH="/Users/_dev/MyProject/MyProject/:$PYTHONPATH"
export PYTHONPATH

到/User/_dev/.bash_profile

然后 echo $PYTHONPATH 说

/Users/_dev/MyProject/MyProject/:

我做错了什么?非常欢迎任何帮助。

干杯约尔格

最佳答案

只是一个简短的笔记......在 friend 的大力帮助下,我设法完成了它。这是我的设置:

/Library/Server/Web/Config/apache2/httpd_wsgi2.conf

Alias /robots.txt /Users/_dev/hotclub/hotclub/static/robots.txt
Alias /favicon.ico /Users/_dev/hotclub/hotclub/static/img/favicon.ico

Alias /media/ /Users/_dev/hotclub/hotclub/static/media/
Alias /static/ /Users/_dev/hotclub/hotclub/static/

<Directory /Users/_dev/hotclub/hotclub/static>
Order allow,deny
Allow from all
</Directory>

<Directory /Users/_dev/hotclub/hotclub/static/media>
Order allow,deny
Allow from all
</Directory>

WSGIScriptAlias / /Users/_dev/hotclub/hotclub/hotclub.wsgi

<Directory /Users/_dev/hotclub/hotclub>
Order allow,deny
Allow from all
</Directory>

/Library/Server/Web/Config/apache2/webapps/com.apple.webapp.wsgi2.plist

<?xml version="1.0" encoding="UTF-7"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>com.apple.webapp.wsgi2</string>
<key>displayName</key>
<string>Hot Club Setup at /</string>
<key>launchKeys</key>
<array/>
<key>proxies</key>
<dict/>
<key>installationIndicatorFilePath</key>
<string>/Users/_dev/hotclub/hotclub/hotclub.wsgi</string>
<key>includeFiles</key>
<array>
<string>/Library/Server/Web/Config/apache2/httpd_wsgi2.conf</string>
</array>
<key>requiredModuleNames</key>
<array>
<string>wsgi_module</string>
</array>
</dict>
</plist>

/Users/_dev/MyProject/MyProject/MyProject.wsgi

future 导入unicode_literals

import os
import sys

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
#PROJECT_ROOT = "/Users/_dev/hotclub/hotclub"
settings_module = "%s.settings" % PROJECT_ROOT.split(os.sep)[-1]
os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings_module)

sys.path.append('/Users/_dev/hotclub')
sys.path.append('/Users/_dev/hotclub/hotclub')

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

干杯,约尔格

关于python - 使用 Server.app 在 Mac OS X 10.9 上使用 Apache/mod_wsgi 部署 Django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28553133/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com