Python and Web Programming

Slides:



Advertisements
Similar presentations
Tutorial 6 Creating a Web Form
Advertisements

Supplement Creating Forms. Objectives Show how forms are used How to create the Form element HTML elements used for creating input fields.
CGI Programming Part 2. Input Tags Many different ways of getting data from the user. The tag is used most often. has a type attribute –Specifies the.
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
Python, CGI November 23, Unit 8. So Far We can write programs in Python (in theory at least) –Conditionals –Variables –While loops We can create a form.
Creating Web Page Forms. Objectives Describe how Web forms can interact with a server-based program Insert a form into a Web page Create and format a.
Tutorial 6 Working with Web Forms
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
Creating Web Page Forms
1 More JavaScript, HTML Forms, CGI Scripts Tom Horton Alfred C. Weaver CS453 Electronic Commerce.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
Advance Database Management Systems Lab no. 5 PHP Web Pages.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
4-Sep-15 HTML Forms Mrs. Goins Web Design Class. Parts of a Web Form A Form is an area that can contain Form Control/Elements. Each piece of information.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
XP Tutorial 6New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Creating Web Page Forms Designing a Product Registration Form Tutorial.
XP Tutorial 6New Perspectives on HTML and XHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
CO1552 Web Application Development HTML Forms. Websites can be made more interactive by providing facilities for users to provide data To get user entered.
1 Creating Web Forms in HTML Web forms collect information from customers Web forms include different control elements including: –Input boxes –Selection.
Forms and Form Controls Chapter What is a Form?
Lesson 13: Building Web Forms Introduction to Adobe Dreamweaver CS6 Adobe Certified Associate: Web Communication using Adobe Dreamweaver CS6.
1 Forms A form is the usual way that information is gotten from a browser to a server –HTML has tags to create a collection of objects that implement this.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
XHTML Introductory1 Forms Chapter 7. XHTML Introductory2 Objectives In this chapter, you will: Study elements Learn about input fields Use the element.
HTML II. Factors to consider in designing a website. Organizing your files. HTML Tables. Unordered Lists. Ordered Lists. HTML Forms. Learning Objectives.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
Introduction to Programming the WWW I CMSC Summer 2004 Lecture 6.
Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and check boxes using HTML Add a pull-down.
Lecture # 6 Forms, Widgets and Event Handling. Today Questions: From notes/reading/life? Share Personal Web Page (if not too personal) 1.Introduce: How.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
© 2010 Delmar, Cengage Learning Chapter 8 Collecting Data with Forms.
Active Server Pages  In this chapter, you will learn:  How browsers and servers interacted on the Internet when the Internet first became popular 
Chapter 8 Collecting Data with Forms. Chapter 8 Lessons Introduction 1.Plan and create a form 2.Edit and format a form 3.Work with form objects 4.Test.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
LOGO FORMs in HTML CHAPTER 5 Eastern Mediterranean University School of Computing and Technology Department of Information Technology ITEC229 Client-Side.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
HTML FORMS GET/POST METHODS. HTML FORMS HTML Forms HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes,
XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical usage of the form tag in HTML.
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
1 HTML Forms
Microsoft FrontPage 2003 Illustrated Complete Creating a Form.
HTML Form Widgets. Review: HTML Forms HTML forms are used to create web pages that accept user input Forms allow the user to communicate information back.
HTML Forms a form is a container for input elements on a web page input elements contain data that is sent to the web server for processing.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
HTML FORMS The TEXT Object Presented By: Ankit Gupta.
Creating Web Page Forms COE 201- Computer Proficiency.
Week 10: HTML Forms HNDIT11062 – Web Development.
HTML Forms. A form is simply an area that can contain form fields. Form fields are objects that allow the visitor to enter information - for example text.
Copyright (c) 2004 Prentice-Hall. All rights reserved. 1 Committed to Shaping the Next Generation of IT Experts. Project 6: Creating XHTML Forms Kelly.
1 HTML forms (cont.)
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
Tutorial 6 Creating a Web Form
HTML III (Forms) Robin Burke ECT 270. Outline Where we are in this class Web applications HTML Forms Break Forms lab.
FORMS Explained By: Jasdeep Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Lesson 11. CGI CGI is the interface between a Web page or browser and a Web server that is running a certain program/script. The CGI (Common Gateway Interface)
XP Tutorial 6New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
2440: 141 Web Site Administration Web Forms Instructor: Joseph Nattey.
Tutorial 6 Working with Web Forms
Advanced HTML Tags:.
How to Write Web Forms By Mimi Opkins.
Section 17.1 Section 17.2 Add an audio file using HTML
ITE 115 Creating Web Page Forms
HTML Forms and User Input
Presentation transcript:

Python and Web Programming November 21, Unit 8

Web Scripts Programs that generate web pages are often called web scripts or CGI scripts Like using XSL to transform an XML file into an HTML file, we can use web scripts to create web pages for us Why use web scripts? Allows use to dynamically generate web pages These web pages are created upon request Standard HTML files stored on a server are called static web pages or static files They don’t really change (unless we edit the HTML)

Creating Web Pages We can create web pages using a script in many different languages Obviously, we can use Python (since that’s what we’re learning) Other common languages include: Perl PHP ASP

Simple Page in Python Creating a simple web page in Python is very similar to how it was done using XSL Basically, the Python program will need to output the HTML we need for our page To do this, we’ll use a series of print statements The basic things we need are: Header information (text/html) A blank line <html>, <head>, <title>,<body>, HTML content, and closing tags

Simple Python Script print “Content-type: text/html” print print ”<html><head>” print “<title>Python Example</title>” print ”</head><body>” print “<h1>Python is fun</h1>” print “<p> Python made this page</p>” print “</body></html> “

Header Information print “Content-type: text/html” This produces the header information for our web page Basically the purpose of this is to tell the browser which type of information is going to be sent Indicates the MIME type When we put a python script online, it has the extension “.py” Browser needs to know that HTML is coming Why the blank line after the header? Indicates the start of the HTML

Triple-Quoted Strings When we create web pages with Python we can dynamically change parts of the page But large portions of the page may be static Instead of having multiple print statements we can use fewer and enclose much of our HTML in triple quoted strings “’ Allows us to have line breaks where double quotes do not in python

Triple-Quoted String Example print “Content-type: text/html” print print ”””<html><head> <title>Python Example</title> </head><body> <h1>Python is fun</h1> <p> Python made this page</p> <body></html> “”” This produces the same output as the first example Python script Allows us to copy and paste large chunks of HTML

Python Generated Web Pages The previous scripts are kind of pointless to do with Python They actually create static web pages They don’t change But we can generate web pages that do change A simple example is to include the current time on a web page

Adding Time to a Web Page import time print “Content-type: text/html” print print “’<html><head><title>Time Page</title></head>”’ print”<body><p>Right now, the time is <strong> “ print time.asctime(), “</strong></p>” Print “</body></html>”

Output From Last Script Content-type: text/html <html><head><title>Time Page</title></head> <body><p>Right now, the time is <strong>Tue Nov 21 13:45:00 2005 </strong></p> </body></html>

Running Python Scripts When we run this script locally, we see the output from our script What we have on the last slide We don’t see the web page we wanted to create To get the page to display we need to upload it to the cmpt165 server Our webpage will have the URL path of somepage.py We can test our use of the timeasc function by running it in IDLE The output will show up in the window

raw_data vs. Forms Right now we’re using raw_data to get user input But if we’re using a web page, we have no console for the user to enter data into Instead we’ll use forms Forms allow users to enter data into a web page This data is then sent back to the web script on the web server We are familiar with forms We enter information into a form when we use a search engine Purchase items online

Building a Basic Page with a Form The first thing we need is the <form> tag The <form> tag goes around the entire form Does not affect the appearance of the page Just notes where the form begins and ends Just like writing standard HTML <form> needs an attribute called “action” This specifies the action to be taken when the form is submitted

<form>, cont. The action attribute is very important Why have a form that does nothing? action specifies which script to run when the form is submitted The value for action should be the URL of the script <form action = “testScript.py”> <form action = “someFolder/customerInfo.py”>

Adding Controls Controls are those elements which we are going to add to the form Text fields Text areas Check boxes Radio Buttons Selectable Lists Submit button A form without controls is pointless There’s no user input! We are going to add controls using the <input> tag

<input> Tag With the <input> tag we need to specify two attributes: type name Type attribute specifies the type of control Name attribute gives a name to the control so we can access the data in it later Like giving it a variable name

Type Attribute Again, the type attribute specifies the type of control Some examples include: type =“text” - text box type =“checkbox” –check box type =“radio” –radio button type = “submit” –submit button Example: <input type =“submit”…..

Name Attribute We have to have a name to access the information in a particular portion of the form Very similar to naming variables It’s best if the name relates to the content of the control and the control type Ex. A text box control which gets a customer name could have a name= “customerName” A check box control which allows customer to select getting product updates name=“checkUpdates”

Value Attribute Sometimes we’ll also want to add a value attribute The value attribute specifies the default value for that control Ex. <input type=“text” value=“a textbox” name=“textbox1”/> “a textbox” would appear in the text box Checkboxes can use the checked property to indicate if it should be checked by default <input type=“checkbox” checked=“checked” name=“checkbox1”/> If checked=“checked” then the box will appear checked “checked” is the only value that the checked property can have

Other Useful Text Attributes size attribute indicates how wide the text box should be <input type = “text” name=“text1” size =“10”/> Size indicates how many characters, in this case 10 maxlength is just like size except that it indicates the maximum number of characters a text box will accommodate

Submit Type We have to have a way to send the form information to the script that’s going to handle it To do this we can use a control with the type “submit” It will show up as a button The value attribute will indicate the text which should be displayed on the button <input type=“submit” value=“Go” name=“submitButton”/>

HTML Form Example In class Example

What’s Next? So now we can create forms And users can enter information But how the heck do we use it? We are going to use CGI to take the information from the form and process it somehow We’ll get into this next class You’ll be using CGI to take order information

Questions What you should know: What web scripts are How to create a webpage using Python How to use triple quoted strings How to write a form in HTML <form action=“someprogram.py”> <input>