Python – Run python script automatically on apache server

apache-2.2pythonscripting

I have a hello world script written in python called hello.py. I am using apache on a windows machine, and I'd like the script to run automatically, whenever I enter something like http://localhost/

Can someone please tell me how to do this ?

PS: If I point to the script directly from the browser, it displays properly.

hello.py:

#! c:\Python27\python.exe

print "Content-Type: text/html\n\n"
print 'Heya, world..yaba daba doo!'

Best Answer

It sounds like you want your Python script to be the index document?

If your setup already works when you do something like http://localhost/hello.py I would suggest renaming it to index.py (common convention to call an index document "index.something") and then editing your Apache configuration to include index.py inthe DirectoryIndex filenames list.