Django Apache 你好世界
是否有一个 Hello World 教程来让一个最小的 Django 项目与 Apache 一起使用?
或者,谁能告诉我我哪里误入歧途了。我已经完成了 Django 教程,一切似乎都按预期工作,但它们没有介绍如何使用 apache 服务器实际部署示例。我找到了他们关于如何让 Django 与 Apache 一起工作的文档,但是我没有任何运气。我在Ubuntu上。我执行了 apt-get install libapache2-mod-wsgi ,然后按照上面第二个链接上的说明进行操作。
我的 /etc/apache2/httpd.conf 是一行(正常吗?)
WSGIScriptAlias / /home/john/programming/djangotutorial1/mysite/apache/django.wsgi
,我在 /home/john/programming/djangotutorial1/mysite/apache/django.wsgi 创建了一个新文件,如下所示:
import os
import sys
path = '/home/john/programming/djangotutorial1'
if path not in sys.path:
sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
和 mysite已填充的 Django 教程网站。
当访问 mywebsite.com 时,我收到 500 内部服务器错误。
有想法吗?
Is there a Hello World tutorial for getting a minimal Django project working with Apache?
Alternatively, can anybody tell me where I've gone astray. I've gone through the Django tutorials and everything seems to work as expected, but they don't cover how to actually deploy the example with an apache server. I found their documentation about how to get Django working with Apache, but I didn't have any luck with it. I'm on Ubuntu. I did apt-get install libapache2-mod-wsgi
, and then followed the instructions on the second link above.
My /etc/apache2/httpd.conf is a one-liner (is that normal?)
WSGIScriptAlias / /home/john/programming/djangotutorial1/mysite/apache/django.wsgi
And I created a new file at /home/john/programming/djangotutorial1/mysite/apache/django.wsgi that looks like this:
import os
import sys
path = '/home/john/programming/djangotutorial1'
if path not in sys.path:
sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
And mysite the Django tutorial website which is already populated.
When of go to mywebsite.com I get a 500 Internal Server Error.
Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您收到 500 错误,这意味着您的网站至少正在加载。您应该做的是在 settings.py 中启用调试,然后重新启动 Apache。它不会给您 500 错误,而是会向您显示真正的错误是什么。
通常不建议启用调试,但由于它只是一个 Hello World,所以没问题。但在生产环境中,您可以通过查看 Apache 的错误日志来查找问题。
Since you're getting a 500 error, that means your site is at least loading. What you should do is enable Debugging in your settings.py and then restart Apache. Instead of giving you a 500 error, it'll show you what the real error is.
Enabling debugging isn't usually recommended, but since it's just a Hello World, it'll be fine. But in a production environment you can look through Apache's error logs to find the issue.