Django:只有空白页
我有一个带有 Apache 的服务器,我想启动用 Django 编写的网站。我的用户是mod_wsgi。现在我已经准备好了。但服务器的响应是空的。而且错误日志里什么也没有。你知道这是什么原因吗?
如果某个文件可以提供帮助(*.wsgi,settings.py),我将附加它。
Prochazky.wsgi
import os
import sys
import site
os.environ['PYTHON_EGG_CACHE'] = '/home/prochazky/venv/.python-eggs'
site.addsitedir('/home/prochazky/venv/lib/python2.6/site-packages')
os.environ['DJANGO_SETTINGS_MODULE'] = 'Prochazky.settings'
sys.path.append('/home/prochazky/')
sys.path.append('/home/prochazky/Prochazky/')
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Apache 虚拟主机:
<VirtualHost *:80>
WSGIScriptAlias / /home/prochazky/Prochazky/Prochazky.wsgi
ServerName testing.prochazky.net
DocumentRoot /home/prochazky
ErrorLog /home/prochazky/wsgi.log
</VirtualHost>
I have a server with Apache and I would like to start website written in Django. I user mod_wsgi. Now I have it prepared. But the respond of a server is empty. And in error log, there is nothing. Do you know what is the reason why?
If some file could help (*.wsgi, settings.py) I will append it.
Prochazky.wsgi
import os
import sys
import site
os.environ['PYTHON_EGG_CACHE'] = '/home/prochazky/venv/.python-eggs'
site.addsitedir('/home/prochazky/venv/lib/python2.6/site-packages')
os.environ['DJANGO_SETTINGS_MODULE'] = 'Prochazky.settings'
sys.path.append('/home/prochazky/')
sys.path.append('/home/prochazky/Prochazky/')
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Apache vhost:
<VirtualHost *:80>
WSGIScriptAlias / /home/prochazky/Prochazky/Prochazky.wsgi
ServerName testing.prochazky.net
DocumentRoot /home/prochazky
ErrorLog /home/prochazky/wsgi.log
</VirtualHost>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试先让 hello world 程序运行,而不是 Django。观看:
http://code.google.com/p/modwsgi/wiki/WhereToGetHelp? tm=6#Conference_Presentations
并阅读:
http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide
不过猜测一下,您是也许将 mod_python 加载到同一个 Apache 中。不兼容的 mod_python 将导致该症状,并且在主 Apache 错误日志中仅显示分段错误消息。
更新 1
您是否将 mod_php 加载到同一个 Apache 中?有时它可能具有冲突的共享库要求,并会导致崩溃。如果您还加载它,请从 Apache 配置中禁用它。
还可以尝试设置:
这将强制使用主解释器,这将避免未正确编写以在子解释器中工作的第三方扩展的问题。
但您确实需要更仔细地查看主 Apache 错误日志,而不是虚拟主机日志。当您发出请求时,在其上运行“tail -f”,并检查确保您在那里看到消息,特别是分段错误或类似消息。此类有关进程崩溃并导致空页的消息不会显示在虚拟主机错误日志中。
Trying getting a hello world program working first and not Django. Watch:
http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm=6#Conference_Presentations
and read:
http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide
At a guess though, are you perhaps loading mod_python into the same Apache. An incompatible mod_python will cause exactly that symptom with merely a segmentation fault message in main Apache error log.
UPDATE 1
Are you loading mod_php into same Apache? It can sometimes have conflicting shared library requirements and will cause a crash. If you are also loading it, disable it from Apache configuration.
Also try setting:
This will force use of main interpreter which will avoid problems with third party extensions that aren't written properly to work in sub interpreters.
You really though need to look more closely at the main Apache error log, not the virtual host one. Run a 'tail -f' on it when you make a request and check for sure you are seeing messages there, specifically a segmentation fault or similar message. Such a message about process crashing and causing empty page will not show in virtual host error log.
您的根 url/视图的模板文件是否可能为空或计算结果为空?
例如,如果您有这样的模板:
并且 base.html 不使用“内容”块,则不会使用模板中的内容块,并且您的模板将评估为空,尽管有内容。
Is it possible the template file your root url/view is empty or evaluates to empty?
For instance, if you have a template like so:
and base.html doesn't use a block "content", then the content block from your template won't be used and your template will evaluate to empty despite having content.
这是我的设置(更改名称是为了保护
无辜有罪者)。我认为您需要
来允许服务器访问 .wsgi。我确实不是一个 apache 专家,所以不要认为这个例子是完美的。 (我认为所需要的只是
命令允许、拒绝
和允许所有人
)一个值得一看的好网站:http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
This is from my setup (names altered to protect the
innocentguilty).I think you need the
<directory>
to allow the server to access the .wsgi.I'm really not an apache guru though so don't take this example as perfect. (I think all that is needed is the
order Allow, deny
andallow from all
)a good site to check out: http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango