繁体   English   中英

apache2上的python 404错误

[英]404 error with python on apache2

我在/var/www有一个文件test.py ,并且在ubuntu 10.10上使用apache2 我已经安装了mod_python并将/etc/apache2/sites-available/default配置为

<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride AuthConfig
    Order allow,deny
    allow from all

    AddHandler mod_python .py
    PythonHandler mod_python.publisher
    PythonDebug On

    # Uncomment this directive is you want to see apache2's
    # default start page (in /apache2-default) when you go to /
    #RedirectMatch ^/$ /apache2-default/
</Directory>

如果放

def index(req):
  return "Test successful";

然后我得到Test successful

如果我放

#!/usr/bin/env python
print "Content-Type: text/html"
print
print """\
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
"""

我得到404: Not found错误

这里可以找到更多

任何人有任何想法吗?

问候,

experimentX

mod_python尝试处理请求时,默认情况下会查找方法def index(req) ,否则,您可以在URL中指定要调用的函数。 请注意,该函数必须返回特定值。

所以你可以做点什么

s ="""\
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
"""

def index():
   return s

此处说明了 mod_python下的url travelsal

我建议您使用mod_wsgi代替mod_python因为有许多使用WSGI的框架,例如FlaskCherryPyBottle等。

这些框架的妙处在于,您甚至不必在开发计算机上使用Apache,而可以使用其内置的测试服务器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM