Download presentation
Presentation is loading. Please wait.
Published byAngelica Gardner Modified over 9 years ago
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: A.Modify the HTML File: MyFamilyHistory.html B.Set Up the cgi file C.Set Up the Database D.Making life easier (use a “dictionary”) E.Processing the Form (write python functions) F.Modify the generateHTMLPage function G.Test it and Link it Up
7
Here are the Steps A through G: A.Modify the HTML File: MyFamilyHistory.html B.Set Up the cgi file C.Set Up the Database D.Making life easier (use a “dictionary”) E.Processing the Form (write python functions) F.Modify the generateHTMLPage function G.Test it and Link it Up
8
A: Modify the HTML File: MyFamilyHistory.html 1. 1.Set the action attribute in to: 1.Name all necessary widgets. For example 1.Insert the list of people (string %listOfPeople%) Copy MyFamilyHistory.html HTML_CS S Server1 YourAccountName
9
Here are the Steps A through G: A.Modify the HTML File: MyFamilyHistory.html B.Set Up the cgi file C.Set Up the Database D.Making life easier (use a “dictionary”) E.Processing the Form (write python functions) F.Modify the generateHTMLPage function G.Test it and Link it Up
10
B: Set up the cgi file Copy the MFH.cgi file from HTML_CSS folder to the Server1 folder Copy MFH.html HTML_CS S Server1
11
Here are the Steps A through G: A.Modify the HTML File: MyFamilyHistory.html B.Set Up the cgi file C.Set Up the Database D.Making life easier (use a “dictionary”) E.Processing the Form (write python functions) F.Modify the generateHTMLPage function G.Test it and Link it Up
12
C: Set up the Database – Step 1 1. Modify initializeWithNames.py so that it has your names Run createDB.py and initializeWithNames.py by double clicking on them, in that order Copy createDB.py HTML_CS S Server1 initializeWithNames.py
13
C: Set up the Database – Step 2 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: A.Modify the HTML File: MyFamilyHistory.html B.Set Up the cgi file C.Set Up the Database D.Making life easier (use a “dictionary”) E.Processing the Form (write python functions) F.Modify the generateHTMLPage function G.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: A.Modify the HTML File: MyFamilyHistory.html B.Set Up the cgi file C.Set Up the Database D.Making life easier (use a “dictionary”) E.Processing the Form (write python functions) F.Modify the generateHTMLPage function G.Test it and Link it Up
18
E: Processing the Form – Step 1 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: A.Modify the HTML File: MyFamilyHistory.html B.Set Up the cgi file C.Set Up the Database D.Making life easier (use a “dictionary”) E.Processing the Form (write python functions) F.Modify the generateHTMLPage function G.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 replace method:
24
Here are the Steps A through G: A.Modify the HTML File: MyFamilyHistory.html B.Set Up the cgi file C.Set Up the Database D.Making life easier (use a “dictionary”) E.Processing the Form (write python functions) F.Modify the generateHTMLPage function G.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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.