250 likes | 423 Vues
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:.
E N D
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: • 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
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
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
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
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
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
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
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}
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():
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
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%": "”}
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
E: Processing the Form – Step 1 • Create the processForm() function called by the main routine and insert it after the openDB() function
E: Processing the Form – Step 2 2. Create the addPerson() function called by the function processForm() function
E: Processing the Form – Step 3 3. Create the deleteSelectedPerson() function called by the function processForm() :
E: Processing the Form – Step 4 4. Create the createListOfPeople() function called by the function processForm() :
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
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:
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
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.