404 error with python on apache2
I have a file test.py
at /var/www
and I am using apache2
on ubuntu 10.10. I have mod_python
installed and /etc/apache2/sites-available/default
configured as
<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/
</Director开发者_如何转开发y>
If it put
def index(req):
return "Test successful";
Then i get Test successful
And if i put
#!/usr/bin/env python
print "Content-Type: text/html"
print
print """\
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
"""
I get 404: Not found
error
More can be found here
Anyone any ideas ??
Regards,
experimentX
mod_python looks for method def index(req)
by default when it tries to handle your requests, otherwise you can specify the function which you want to call in the URL. Note that function has to return a specific value.
So you can do something like
s ="""\
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
"""
def index():
return s
The url travelsal under mod_python is illustrated here.
Instead of mod_python
I would suggest you to use mod_wsgi
as there are many WSGI-using frameworks like Flask, CherryPy, Bottle, etc...
Cool thing with these frameworks is that you don't even have to use the Apache on your development machine, but instead can use their builtin test-server.
精彩评论