Web Python Question
Question: Can anyone assist me in getting a Python script running on Hostgator Shared
hosting? I work with PHP mostly, but have taken a liking to Python, and would
like to try to get it going on the web. The only way I've ever ran Python is
with either the interpreter, or through a terminal, with >Python file.py. I
tried just uploading a hello world file to the webserver, but all it outputs
is the script source. I talked with hostgator, but all they could tell me was
I need to use a dispatcher, which I cannot seem to find an example of. All I
want to know, is how to make a <p>Hello</p> output to the browser.

Thanks, and sorry if I'm rambley, I've been Googling this off and on all week
now.


Answer: Well, I got [this](http://support.hostgator.com/articles/getting-
started/general-help/perl-and-python-
http://docs.python.org/library/cgiscripts) from Hostgator's own support site.

Assuming your host is running Python 2.x, then you can adapt the linked-to
script as follows:

    
    
    #!/usr/bin/python
    print "Content-type: text/html\r\n\r\n"
    print "<html><head>"
    print "<title>CGI Test</title>"
    print "</head><body>"
    print "<p>Test page using Python</p>"
    print "</body></html>"
    

and put it in your `cgi-bin` folder with permissions of 755.

**Update:** In terms of "getting around" the cgi-bin folder: that'll depend on
options your hosting package allows. Look at [Bottle](http://bottle.paws.de/)
for a simple dispatcher which fits in a single Python module. You can deploy
it using CGI,

    
    
    import bottle
    # Put your bottle code here, following the docs on the Bottle site
    bottle.run(server=bottle.CGIServer)
    

**Further update:** Apart from the Bottle docs, I suggest you read the [Python
docs about CGI](http://docs.python.org/library/cgi).

