Web App with Database - Computer Science

5 downloads 2033 Views 2MB Size Report
4/1/13. 1. Computer Science. CS108. Data-Driven Web Applications. Python/ MySQL Integration. Organizing Your Web Application. Using HTTP Form Data as  ...
4/1/13

CS108 Data-Driven Web Applications Python/MySQL Integration Organizing Your Web Application Using HTTP Form Data as SQL Query Parameters

Aaron Stevens

Computer Science

Web App with Database

Computer Science

Client (Web Browser)

HTTP Request HTTP Response

Internet

HTTP Request SQL Query

HTTP Response

Result Set

Python Web App (Web Server)

MySQL Database (Server)

1

4/1/13

Integration with sqlite3 Computer Science

Recall LAMP: Linux-Apache-MySQL-Python Any of these LAMP architecture components is interchangeable with other similar components…

Integration with MySQL Computer Science

Recall LAMP: Linux-Apache-MySQL-Python The following would connect to a MySQL database.

2

4/1/13

Segregate boiler-plate code

Computer Science

Put this boiler-plate code in its own functions.

Organizing your Web App Computer Science

Separate code which works with the database from code which produces HTML

3

4/1/13

Organizing your Web App Computer Science

Output…. Computer Science

4

4/1/13

__main__ code: Computer Science

Keep the main section as simple as possible.

Integrating a Search Form

Computer Science

Use a separate function to display this form.

5

4/1/13

SQL SELECT Code… Computer Science

__main__ code: Computer Science

Keep the main section as simple as possible. Note: we’ve added a choice based on form fields:

6

4/1/13

How to Insert Data Computer Science

Use another form, and another function to display this form.

How to Insert Data Computer Science

Use another form, and another function to display this form.

7

4/1/13

__main__ code: Computer Science

Keep the main section as simple as possible.

SQL Insert Code… Computer Science

8

4/1/13

__main__ code: Computer Science

Keep the main section as simple as possible.

How to Update Data Computer Science

Use another form, and another function to do SQL.

9

4/1/13

How to Update Data Computer Science

Use another form, and another function to display this form.

__main__ code: Computer Science

Keep the main section as simple as possible.

10

4/1/13

Implementing ordering Computer Science

Notice that we are pre-filling some form fields.!

Implementing Ordering Computer Science

11

4/1/13

Implementing links for Next/Back

Computer Science

What You Learned Today Computer Science

  Database integration points   Using functions to decompose web applications

12

Suggest Documents