1

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!'

3 Answers 3

1

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.

2

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.

1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .