Forums

Testing simple CGI stuff

Hi,

At the beging I want to apologize for my English... OK. Currently I'm reading "Programming Pyton" by Mark Lutz. In this book there are a few chapters about writing CGI scripts and other Internet related stuff. Obviously to test this kinda code I need some hosting place. So I came across this website I reigster myself and... I stucked.

I just want to run those simple HTML/Python codes (examples from book):

cgi101.html : http://pastebin.ubuntu.com/6577909/

cgi-bin/cgi101.py : http://pastebin.ubuntu.com/6577914/

While trying to achive this I added "Manual configuration" (Python 3.3) as "new web app" and I edited file ( /var/www/petermakal_pythonanywhere_com_wsgi.py) to this:

import sys

path = '/home/petermakal/'

if path not in sys.path:

sys.path.append(path)

Then I run my cgi101.html in browser (http://petermakal.pythonanywhere.com/database5_CGI/cgi101.html). I type something, I click button and then my Python script should be executed (http://petermakal.pythonanywhere.com/database5_CGI/cgi-bin/cgi101.py)... but all I see at this point is "Unhandled Exception" in my browser.

Really all I need at this point is to just test that simple HTML/Python code showed above.

Hi there -- CGI is a pretty uncommon way of doing web apps these days -- it's really inefficient because every time someone requests a page, a Python interpreter has to be started up and run to handle it. That makes everything really slow and means that a site can't handle more than a couple of visitors.

WSGI is a more modern way of doing these things; you have a number of Python programs running constantly (we call them "web workers" here) and because they're already there, everything's much faster.

PythonAnywhere only supports WSGI, so unfortunately the examples you're using won't work. You might be better off following a tutorial on more modern web development. This is a great one for web2py, which is a good framework to learn if it's your first one.

Thanks giles for all informations. Well I definetlly will check this link you gave but firstly I want to go through Mark Lutz book. I think I finally found good place to test book examples but I have to wait for my account activation now. Nevertheless once again thanks for all informations :)

@petermakal: You can't beat the community here at PA. I hope you find a way to benefit from what is offered here!