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!'
link|improve this question
feedback

3 Answers

up vote 1 down vote accepted

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.

link|improve this answer
feedback

I'd highly recommend you write your app (however simple) around a framework. It makes everything massively easier, and you don't end up reinventing wheels. I tend to use Django, or CherryPy.

I recommend you give Cherry a look. The homepage details how to make a Hello World application.
Then all you need to do is ProxyPass to it from Apache, or use mod_wsgi and let apache communicate directly with the application.

link|improve this answer
feedback

Is your DirectoryIndex set appropriately in your httpd.conf file?

For example, my DirectoryIndex line is as follows - you should add hello.py to the list (although index.py may be more conventional).

DirectoryIndex index.php index.html

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.