Django:只有空白页

发布于 2024-11-26 22:26:30 字数 906 浏览 2 评论 0原文

我有一个带有 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 技术交流群。

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

发布评论

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

评论(3

当爱已成负担 2024-12-03 22:26:30

尝试先让 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 配置中禁用它。

还可以尝试设置:

WSGIApplicationGroup %{GLOBAL}

这将强制使用主解释器,这将避免未正确编写以在子解释器中工作的第三方扩展的问题。

但您确实需要更仔细地查看主 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:

WSGIApplicationGroup %{GLOBAL}

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.

余生共白头 2024-12-03 22:26:30

您的根 url/视图的模板文件是否可能为空或计算结果为空?

例如,如果您有这样的模板:

{% extends "base.html" %}
{% block content %}blah blah{% endblock %}

并且 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:

{% extends "base.html" %}
{% block content %}blah blah{% endblock %}

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.

情话墙 2024-12-03 22:26:30

这是我的设置(更改名称是为了保护无辜有罪者)。

<VirtualHost *:80>
        ServerName site.domain.com 
        ServerAdmin [email protected] 

        WSGIScriptAlias / /home/user/site/django.wsgi

        <Directory /home/user/site/>
                Options FollowSymLinks
                AllowOverride None 
                Order allow,deny
                allow from all
        </Directory>
         ... etc etc etc.

我认为您需要 来允许服务器访问 .wsgi。
我确实不是一个 apache 专家,所以不要认为这个例子是完美的。 (我认为所需要的只是命令允许、拒绝允许所有人

一个值得一看的好网站:http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

This is from my setup (names altered to protect the innocent guilty).

<VirtualHost *:80>
        ServerName site.domain.com 
        ServerAdmin [email protected] 

        WSGIScriptAlias / /home/user/site/django.wsgi

        <Directory /home/user/site/>
                Options FollowSymLinks
                AllowOverride None 
                Order allow,deny
                allow from all
        </Directory>
         ... etc etc etc.

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 and allow from all)

a good site to check out: http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

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