在 Apache 上设置 django 时出现问题
这可能真的很简单。但我想我对 WSGI 和 Django 太陌生,无法自己获得它。我在 /var/www/mysite 中托管的 Ubuntu 虚拟机上有一个全新的闪亮 Django 项目。该项目是通过
django-admin startproject mysite
我遵循 WSGI 教程来进行设置的,因此我创建了一个 ./apache 文件夹,在其中放置了此文件 django.wsgi:
import os
import sys
os.environ['DJANGO_SETTINGS_MODULE'] = '/var/www/mysite/mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
然后我将此配置行添加到 Apache 配置中:
WSGIScriptAlias / /var/www/mysite/apache/django.wsgi
当我尝试访问该网站时,没有返回任何内容。连接只是挂起。这是在我的 access.log 中:
192.168.2.116 - - [15/Aug/2010:14:09:02 -500] "GET / HTTP/1.1" 500 639 "-" "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8
所以它正在访问该网站。但有人什么也没做。 error.log 中没有错误。
有人有什么想法吗?
This is probably really simple. But I guess I'm too new to WSGI and Django to get it on my own. I have a brand new shiny Django project on a Ubuntu virtual machine hosted in /var/www/mysite. The project was created with
django-admin startproject mysite
I'm following a WSGI tutorial to get it set up, so I created an ./apache folder, inside of which I placed this file, django.wsgi:
import os
import sys
os.environ['DJANGO_SETTINGS_MODULE'] = '/var/www/mysite/mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I then added this config line to the Apache configuration:
WSGIScriptAlias / /var/www/mysite/apache/django.wsgi
When I try to hit the site, nothing is returned. The connection just hangs. This is in my access.log:
192.168.2.116 - - [15/Aug/2010:14:09:02 -500] "GET / HTTP/1.1" 500 639 "-" "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8
So it's hitting the site. But someone isn't doing anything. There are no errors in the errors.log.
Anyone have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
原始问题中的明显错误是:
需要是:
也就是说,Django 设置模块必须是 Python 包路径,而不是绝对文件系统路径。接受的答案甚至没有指出这一点,而只是提供了另一组可供使用的代码,没有任何解释。
此外,您需要设置Python模块搜索路径,即sys.path,以便Python可以找到该环境变量中列出的设置文件。
最后,如果您的浏览器挂起,您也做了其他错误的事情,因为您所做的应该导致返回错误,而不是浏览器挂起。 Apache 错误日志中也一定有错误,因此您要么查找错误的位置,要么不知道要查找什么。
The blatant mistake in original question is that:
would need to be:
That is, Django settings module must be a Python package path, NOT an absolute file system path. The accepted answer doesn't even point that out and rather just gives another set of code to use with no explanation.
Further, you need to set Python module search path, ie., sys.path, so that Python can find your settings file listed in that environment variable.
Finally, if your browser was hanging you have done something else wrong as well, as what you did should have resulted in an error being returned and not the browser hanging. There would also have had to be an error in the Apache error log, so you are either looking in wrong place or don't know what to look for.
您是否缺少 Django 应用程序的路径?我的
app.wsgi
有这个:Aren't you missing path to your Django application? My
app.wsgi
has this: