Page 333 -
P. 333

manage your data




                              Let’s turn the HTML form from the previous page into a template within the yate.py module.
                           1  Start by creating a new template called templates/form.html that allows you to
                              parameterize the form’s CGI script name, method, input tags, and submit button text:













                   With the template ready, write the code for two functions you intend to add to yate.py.
              2
                   The first, called create_inputs(), takes a list of one of more strings and creates HTML <INPUT> tags
                   for each string, similar to the one that accepts TimeValue on the previous page.
                   The second, called do_form(), uses the template from Part 1 of this exercise together with the create_
                   inputs() function to generate a HTML form.
                                                                        Given a list of <INPUT>
                              def create_inputs(inputs_list):           tag names.











              Return the
              generated tags to                                   The name of the CGI script and a list of
              the caller.          return(html_inputs)            <INPUT> tag names are required arguments.


                              def do_form(name, the_inputs, method="POST", text="Submit"):

                                                                                  The HTTP method and text
                                                                                  to the “Submit” button have
                                                                                  sensible default values.


            Substitute the
            arguments and
            generated <INPUT>
            tags into the
            template to create       return(form.substitute(cgi_name=name, http_method=method,
            the form.                        list_of_inputs=inputs, submit_text=text))


                                                                                      you are here 4    297
   328   329   330   331   332   333   334   335   336   337   338