试图建立Apache和Django的在一起的时候空白页 [英] Blank page when trying to set up Apache and Django together

查看:210
本文介绍了试图建立Apache和Django的在一起的时候空白页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立Python和Django的与Apache的共同努力。

I'm trying to set up Python and Django to work together with Apache.

Django的项目给我的只是一个空白页,所以我尝试了样品,我在很多地方找到:

The Django project gave me nothing but a blank page, so I've tried a sample I've found in many places:

def application(environ, start_response):

    status = '200 OK'
    output = 'This is my Website!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

我在我的app.py文件的开头添加以下行:

I've added the following lines at the beginning of my app.py file:

#!C:/Program Files/Python34/python.exe
print('Content-Type: text/html')
print('\n\n')

我仍然得到一个空白页。

I still get a blank page.

如果我添加以下code:

If I add the following code:

def testFunction(text):
    print(text)
testFunction('this works')

我得到适当的输出('这工作'),所以我想我的Python脚本的的运行。但是,我怎么得到调用应用程序(ENVIRON,start_response)被称为?

I get the appropriate output ('this works') so I guess my Python script is running. But how do I get the callable application(environ, start_response) to be called ?

我很新到Python / Django和有些新的Apache的,所以我可能会丢失一些小事,但这里是我试过:

I'm very new to Python/Django and somewhat new to Apache so I may be missing something trivial, but here's what I've tried:


  • 展望Apache日志文件,但没有什么在error.log中(即使我已经设置loglevel改为'信息')

  • 确保没有其他模块可以干扰(不mod_php的或mod_python的加载)

  • 添加WSGIApplicationGroup%{} GLOBAL

  • 不使用任何虚拟主机或VIRTUALENV保持它的简单

  • 在文件和文件夹权限检查(所有已阅读和放大器;执行检查)

下面是我的Apache的配置文件的部分:

Here is the section of my Apache config file:

WSGIScriptAlias /wsgi "C:/PythonWorkspace/app.py"

<Directory "C:/PythonWorkspace">    
    Options ExecCGI
    AddHandler cgi-script .cgi .py    
    Require all granted
</Directory>

配置为:在Windows Server 2008 / Apache的2.4瓦特的mod_wsgi / Python的3​​.4 / 1.6.5 Django的

Config is: Windows Server 2008 / Apache 2.4 w MOD_WSGI / Python 3.4 / Django 1.6.5

预先感谢任何指针!

推荐答案

这code是用于 CGI

print('Content-Type: text/html')
print('\n\n')

print('This is my Website!')

这是code是用于 WSGI

def application(environ, start_response):

    status = '200 OK'
    output = 'This is my Website!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

Apache的配置为使用 CGI 的.py 文件

AddHandler cgi-script .cgi .py    

要使用 WSGI 需要

AddHandler cgi-script .cgi # removed .py
AddHandler wsgi-script .py 

这篇关于试图建立Apache和Django的在一起的时候空白页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆