I want to run a Python CGI on a shared hosting environment. I followed Flask's example and came up with a tiny application as below:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
@app.route("/pi")
def pi():
return "3.1416"
if __name__ == "__main__":
app.run()
My .htaccess
contains:
Options +ExecCGI
AddHandler cgi-script .cgi .py .rb
DirectoryIndex index.cgi index.htm
And my index.cgi
is
#!/usr/bin/env python
from wsgiref.handlers import CGIHandler
from firstflask import app
CGIHandler().run(app)
It successfully maps the path /
to index()
, however it fails to map the path /pi
to pi()
, instead returning a 404 error. I guess I miss something obvious. Thanks for the help.
<VirtualHost *>
first? It will be nice if I can pull this off from my PHP-friendly hosting plan. – Candicecandid1and1.com
lacks proper support for Python/Django. The performance penalty and amount of time you will spend fighting the environment is not worth. – Xerophagy