1 / 25

Lecture # 32.1 Lab 10: Server 1

Lecture # 32.1 Lab 10: Server 1. Lab 10 Server 1. Add and delete names. Lab 10 Server 1. from a pull-down/select list. Lab 10 Server 1. and store them in a name database:. Server. Name Database. Lab 10 Server 1. DEMO. Here are the Steps A through G:.

ali-newton
Télécharger la présentation

Lecture # 32.1 Lab 10: Server 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture # 32.1 Lab 10: Server 1

  2. Lab 10 Server 1 Add and delete names

  3. Lab 10 Server 1 from a pull-down/select list

  4. Lab 10 Server 1 and store them in a name database: Server Name Database

  5. Lab 10 Server 1 DEMO

  6. Here are the Steps A through G: • Modify the HTML File: MyFamilyHistory.html • Set Up the cgi file • Set Up the Database • Making life easier (use a “dictionary”) • Processing the Form (write python functions) • Modify the generateHTMLPage function • Test it and Link it Up

  7. Here are the Steps A through G: • Modify the HTML File: MyFamilyHistory.html • Set Up the cgi file • Set Up the Database • Making life easier (use a “dictionary”) • Processing the Form (write python functions) • Modify the generateHTMLPage function • Test it and Link it Up

  8. A: Modify the HTML File: MyFamilyHistory.html Copy HTML_CSS Server1 • Set the action attribute in to: • Name all necessary widgets. For example • Insert the list of people (string %listOfPeople%) MyFamilyHistory.html YourAccountName

  9. Here are the Steps A through G: • Modify the HTML File: MyFamilyHistory.html • Set Up the cgi file • Set Up the Database • Making life easier (use a “dictionary”) • Processing the Form (write python functions) • Modify the generateHTMLPage function • Test it and Link it Up

  10. B: Set up the cgi file HTML_CSS Server1 Copy the MFH.cgi file from HTML_CSS folder to the Server1 folder Copy MFH.html

  11. Here are the Steps A through G: • Modify the HTML File: MyFamilyHistory.html • Set Up the cgi file • Set Up the Database • Making life easier (use a “dictionary”) • Processing the Form (write python functions) • Modify the generateHTMLPage function • Test it and Link it Up

  12. C: Set up the Database – Step 1 Copy HTML_CSS Server1 Modify initializeWithNames.pyso that it has your names Run createDB.pyandinitializeWithNames.pyby double clicking on them, in that order createDB.py initializeWithNames.py

  13. C: Set up the Database – Step 2 • Modify MFH.cgi to include theses four lines at the end: openDB() {Opens External DB; copies names to Internal DB} processForm() {Adds/Deletes names to/from Internal DB} print generateHTMLPage(variables) {Generates new html page to be sent back to Client} closeDB() {Copies names from Internal DB to External DB} Add the following python constructs for the Internal DB: names = [] {[] defines names as an empty list} mothers = {} {{} declare mothers and fathers as fathers = {} empty dictionaries}

  14. C: Set up the Database – Step 3 3. Modify MFH.cgi to read and write from the database: Insert the line “import squlite3” Insert the functions openDB() and closeDB():

  15. Here are the Steps A through G: • Modify the HTML File: MyFamilyHistory.html • Set Up the cgi file • Set Up the Database • Making life easier (use a “dictionary”) • Processing the Form (write python functions) • Modify the generateHTMLPage function • Test it and Link it Up

  16. D: Making life easier (use a dictionary) Organize the keywords with the text that is to replace the keywords in the html document using a dictionary.   To define and initialize this dictionary put the following in the cgi file right after the cgitb.enable() statement: • variables ={"%newName%":          "",            "%errorMessageArea%": "",            "%listOfPeople%":     "”}

  17. Here are the Steps A through G: • Modify the HTML File: MyFamilyHistory.html • Set Up the cgi file • Set Up the Database • Making life easier (use a “dictionary”) • Processing the Form (write python functions) • Modify the generateHTMLPage function • Test it and Link it Up

  18. E: Processing the Form – Step 1 • Create the processForm() function called by the main routine and insert it after the openDB() function

  19. E: Processing the Form – Step 2 2. Create the addPerson() function called by the function processForm() function

  20. E: Processing the Form – Step 3 3. Create the deleteSelectedPerson() function called by the function processForm() :

  21. E: Processing the Form – Step 4 4. Create the createListOfPeople() function called by the function processForm() :

  22. Here are the Steps A through G: • Modify the HTML File: MyFamilyHistory.html • Set Up the cgi file • Set Up the Database • Making life easier (use a “dictionary”) • Processing the Form (write python functions) • Modify the generateHTMLPage function • Test it and Link it Up

  23. F: Modify the generateHTMLPage function Modify the generateHTMLPage() function to replace the keywords %newName%, %errorMessageArea% and %listOfPeople% in the html document with the corresponding values in the dictionary in variables. Do this using the replacemethod:

  24. Here are the Steps A through G: • Modify the HTML File: MyFamilyHistory.html • Set Up the cgi file • Set Up the Database • Making life easier (use a “dictionary”) • Processing the Form (write python functions) • Modify the generateHTMLPage function • Test it and Link it Up

  25. G: Test it and link it up Make sure the “Add Person” and the “Delete Person” buttons work. Also make sure that a list of names now appears in the selection list.

More Related