[Tutor] How to create web interface?

Danny Yoo dyoo at hashcollision.org
Tue May 20 22:41:47 CEST 2014


> I don't understand how precisely the web page would communicate with
> the python program.


Whenever you're communicating to a web site, you are contacting a live
program, a "web server".

In typical usage, a web server delivers static files from its file
system.  But it doesn't have to be that way.  The server is running an
arbitrary program.  When we use the term "web page", we're hiding a
lot of the fundamental, dynamic details: there's a program that's
backing the generation of a web page.


See:

    https://developers.google.com/appengine/docs/python/gettingstartedpython27/helloworld

for example.


In contrast to traditional programs, in web programs, the "entry
point" is no longer a main function.  Instead, your program is
continuously running, and you're in a loop that responds to web
requests.  In the example above, the loop is implicit, because the
framework is doing the looping for us, and calling into our code for
each request.

Other frameworks make the loop a lot more explicit. e.g.

   https://docs.python.org/2/library/basehttpserver.html#more-examples

where you can see that there's a while loop that handles "requests".


A "web request" will happen when someone is visiting your "web page",
or when you're submitting a form to the "web page".  Those requests
hit the server, and that's where you can do something to interact with
the user.  You treat the values of form elements as if they were
parameters, and you treat the request handling as if it were a regular
function call.  The output of the "function call" will be the response
that's sent back to the web browser.


More information about the Tutor mailing list