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
View source of CGI script
View output of CGI script
You can do quite a bit more with CGI scripts
Presenter Notes
Example: Letting the user select which graphs to view
Suppose you have multiple graphs to present
One option would be to simply list them all on a page
View example
Another is to let the user choose which graphs to view using an HTML form
View example
View form source
View CGI script source
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
Goal: let the user select which graphs to view
View example
View form source
View CGI script source
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
Table of Contents
Table of Contents
Using CGI in web interfaces
1
Using Python to generate HTML on the fly
2
Example: Letting the user select which graphs to view
3
Quick review of HTML forms
4
Back to the example
5
What else might you want to do with HTML forms?
6
A note on AJAX
7
Help
Help
Table of Contents
t
Exposé
ESC
Full screen slides
e
Presenter View
p
Source Files
s
Slide Numbers
n
Toggle screen blanking
b
Show/hide slide context
c
Notes
2
Help
h