Using CGI in web interfaces

Presenter Notes

Using Python to generate HTML on the fly

  • We have learned how to use CGI to run Python code on a web server to generate HTML on the fly
  • This saves us the step of creating the HTML code as a separate file beforehand
  • Example CGI scripts
  • You can do quite a bit more with CGI scripts

Presenter Notes

Example: Letting the user select which graphs to view

Presenter Notes

Quick review of HTML forms

  • HTML forms use different tag names to represent input types
    • radio, text, checkbox, ...
    • These tags have two key parameters that identify the part of the form (name) and the selection (value)
    • A special submit button is used to pass the data to a CGI script identified by the action attribute in a form tag
  • For more info on HTML forms, see the CS 110 lecture on forms
  • CGI programming in python
    • the cgi library has a method called cgi.FieldStorage() that includes a dictionary mapping form tag names to the values selected by users

Presenter Notes

Back to the example

Presenter Notes

What else might you want to do with HTML forms?

  • Google Chart Tools can handle only so much data at a time
  • Data over 100Kbytes, or a few thousand lines of code, can generate noticeable lag
  • Sending all your data in the browser to render graphs can be inefficient
  • Using an HTML form to select the subset of data to graph is a good workaround

Presenter Notes

A note on AJAX

  • The Google controls and dashboards allow users to select subsets of data, which then dynamically update the graphs accordingly
    • This is very cool
    • This is an example of AJAX (Asynchronous JavaScript and XML)
    • Want to learn more about this? Take CS 304 Spring 2013
  • We are limited to what can be supported by Google's AJAX library
    • Using a form to filter before sending data to Google Chart Tools may be your only option

Presenter Notes