CS2021-Week 9 - Forms. HTML Forms. Python Web Development. h?ps://www.udacity.com/wiki/ cs253/unit-2html. Form for Submitting input:

Similar documents
Example. Section: PS 709 Examples of Calculations of Reduced Hours of Work Last Revised: February 2017 Last Reviewed: February 2017 Next Review:

App Engine Web App Framework

App Engine Web App Framework

Hons. B.Sc. Degree in Software Engineering/Development. Web and Cloud Development

CSE 115. Introduction to Computer Science I

Computer Grade 5. Unit: 1, 2 & 3 Total Periods 38 Lab 10 Months: April and May

web.py Tutorial Tom Kelliher, CS 317 This tutorial is the tutorial from the web.py web site, with a few revisions for our local environment.

webapp2 Documentation

CHIROPRACTIC MARKETING CENTER

MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY

Building Python web app on GAE

MAP OF OUR REGION. About

CS2021- Week 10 Models and Views. Model, View, Controller. Web Development Model, Views, Controller Templates Databases

MAP OF OUR REGION. About

Grid Code Planner EU Code Modifications GC0100/101/102/104

JAVASCRIPT LOOPS. Date: 13/05/2012 Page: 1 Total Chars: 4973 Total Words: 967

Reverse Segmentable GainMaker Node OIB Shorting Condition Technical Bulletin

Use Statistics for Electronic Government Publications

hereby recognizes that Timotej Verbovsek has successfully completed the web course 3D Analysis of Surfaces and Features Using ArcGIS 10

VTC FY19 CO-OP GOOGLE QUALIFICATIONS PARAMETERS & REIMBURSEMENT DOCUMENTATION HOW-TO

VTC CO-OP GOOGLE QUALIFICATIONS PARAMETERS & REIMBURSEMENT DOCUMENTATION HOW-TO

/Internet Random Moment Sampling. STATE OF ALASKA Department of Health and Social Services Division of Public Assistance

PHP Querying. Lecture 21. Robb T. Koether. Hampden-Sydney College. Fri, Mar 2, 2018

Apple Inc. US 6,587,904 US 6,618,785 US 6,636,914 US 6,639,918 US 6,718,497 US 6,831,928 US 6,842,805 US 6,865,632 US 6,944,705 US 6,985,981

FRIENDS AND FAMILY TEST IN GENERAL PRACTICE

Basic Device Management

CSE 115. Introduction to Computer Science I

Doses Administered Reporting User Instructions

2019 Educational Courses Catalog

Marketing Opportunities

FRIENDS AND FAMILY TEST IN GENERAL PRACTICE

CMPT 165 INTRODUCTION TO THE INTERNET AND THE WORLD WIDE WEB

1 of 8 10/10/2018, 12:52 PM RM-01, 10/10/2018. * Required. 1. Agency Name: * 2. Fiscal year reported: * 3. Date: *

Undergraduate Admission File

Arrays. What if you have a 1000 line file? Arrays

Technical Specifications

Sequential Search (Searching Supplement: 1-2)

Institute For Arts & Digital Sciences SHORT COURSES

Mitel for Microsoft Dynamics CRM Client V5 Release Notes

Calendar Excel Template User Guide

HPE Secur & HPE Secur Cloud

CALENDAR OF FILING DEADLINES AND SEC HOLIDAYS

Workshops. 1. SIGMM Workshop on Social Media. 2. ACM Workshop on Multimedia and Security

Friends and Family Test Survey- Guidance

Guernsey Post 2013/14. Quality of Service Report

April 1, 2018 ATSC Attachment 1 Page 1 of 12 LG Electronics Inc.

EACH MONTH CUTTING EDGE PEER REVIEW RESEARCH ARTICLES ARE PUBLISHED

BERMUDA REGULATORY AUTHORITY (NUMBERING PORTABILITY) GENERAL DETERMINATION 2014 BR 8 / 2014

INTENT TO FILE (ITF)

TEMPLATE CALENDAR2015. facemediagroup.co.uk

April 1, 2019 ATSC Attachment 1 Page 1 of 12 LG Electronics Inc.

COMPUTER TRAINING CENTER

CS4HS Using Google App Engine. Michael Parker

The PHP language. Teaching you everything about PHP? Not exactly Goal: teach you how to interact with a database via web

Form Identifying. Figure 1 A typical HTML form

Mobile Experience. Release Notes. Version: 5.2.x

4. The number of days between 1 January 2017 to date that new admissions to police custody have been halted.

COMPUTER SCIENCE 123. Foundations of Computer Science. 5. Strings

Stat 428 Autumn 2006 Homework 2 Solutions

EXAMINATIONS 2012 MID-YEAR NWEN 241 SYSTEMS PROGRAMMING. The examination contains 5 questions. You must answer ALL questions

DeVry University Houston

eproviderplus Agency Release Notes Version Version Version Version

2015 Editorial Calendar

Lab 4 - Input\Output in VB Using A Data File

Programming Logic and Design Sixth Edition

Text Messaging Calendar

Google App Engine Using Templates

Hitachi-GE Nuclear Energy, Ltd. UK ABWR GENERIC DESIGN ASSESSMENT Resolution Plan for RO-ABWR-0027 Hardwired Back Up System

MRCPI General Medicine Calendar

COMP519 Web Programming Autumn CGI Programming

Update : CalFresh Elimination of Change Reporting in CalFresh

IMPROVING Sepsis SURVIVAL. Data Portal User Manual version 2.0

RLG Model Request for Information (RFI) for Digital Imaging Services

RELEASE NOTES SHORETEL MS DYNAMICS CRM CLIENT VERSION 8

Arrays. Arrays (8.1) Arrays. One variable that can store a group of values of the same type. Storing a number of related values.

MRCPI General Medicine Calendar

CSc 110, Spring Lecture 24: print revisited, tuples cont.

Chapter 19: Twitter in Twenty Minutes

ADP Secure Client User Guide

Special Education Room and Board Reimbursement Claim User Guide

TapeManager, LibraryManager and FileManager Release and Support Policy

YOUR EASY RESPONSIBILITY

Multi-part functionality in PINES

Scheduling. Scheduling Tasks At Creation Time CHAPTER

Understanding Browsers

COMP519 Practical 14 Python (5)

A method is a code block that contains a series of statements. Methods. Console.WriteLine(); Console.ReadKey(); Console.ReadKey(); int.

Read and fill in this page now. Your lab section day and time: Name of the person sitting to your left: Name of the person sitting to your right:

Do not turn to the next page until the start of the exam.

IEPPLUS Special Education Management

IEPPLUS Special Education Management

Sample: n=2,252 national adults, age 18 and older, including 1,127 cell phone interviews Interviewing dates:

IEPPLUS Special Education Management

LIHP Monthly Aggregate Reporting Instructions Manual. Low Income Health Program Evaluation

Lesson 1: Creating a Worksheet and a Chart Microsoft Excel 2016 IN THIS CHAPTER, YOU WILL LEARN HOW TO

UNIVERSITY REFERENCING IN GOOGLE DOCS WITH PAPERPILE

COMP519 Web Programming Autumn CGI Programming

Dictionaries. By- Neha Tyagi PGT CS KV 5 Jaipur II Shift Jaipur Region. Based on CBSE Curriculum Class -11. Neha Tyagi, KV 5 Jaipur II Shift

Web Focused Programming With PHP

Dashboard. 16 Jun Jun 2009 Comparing to: 16 Jun Jun % Bounce Rate. 62,921 Visits. 407,003 Page Views

Transcription:

CS2021-Week 9 - Forms Python Web Development HTML Forms h?ps://www.udacity.com/wiki/ cs253/unit-2html Form for Submitting input: <form> <input name="q"> <input type="submit"> </ form> Web Application: import webapp2 form = """ <form acqon="h?p://www.google.com/ search"> <input name="q"> <input type="submit"> </form> "" class MainPage(webapp2.RequestHandler): def get(self): #self.response.headers['content-type'] = 'text/ plain' self.response.out.write(form)

app = webapp2.wsgiapplicaqon([('/', MainPage)], debug=true) More Handlers import webapp2 form = """ <form acqon="/tes`orm"> <input name="q"> <input type="submit"> </form> """ class MainPage(webapp2.RequestHan dler): def get(self):

#self.response.headers['content- Type'] = 'text/plain' self.response.out.write(form) class TestHandler(webapp2.RequestH andler): def get(self): q=self.request.get("q") self.response.out.write(q) app = webapp2.wsgiapplicaqon([('/', MainPage), ('/tes`orm',

TestHandler)], debug=true) ValidaQon of Input import webapp2 form = """ <form method="post"> <input name="q"><input type="submit"> </form> """ class MainPage(webapp2.Request Handler): def get(self):

self.response.out.write( form) def post(self): self.response.out.write( "Thanks! Valid day!") app = webapp2.wsgiapplication( [('/', MainPage)], debug=true) Responding Based on ValidaQon def post(self): user_month = valid_month(self.request.get('month'))

user_day = valid_day(self.request.get('day')) user_year = valid_year(self.request.get('year')) if not(user_month and user_day and user_year): self.response.out.write(form) else: self.response.out.write("thanks! That's a totally valid day!") Exercise: Write funcqons valid_month(), valid_day(), valid_year(). And then run your code to test your soluqons. # ----------- # User Instructions # # Modify the valid_month() function to verify # whether the data a user enters is a valid # month. If the passed in parameter 'month' # is not a valid month, return None. # If 'month' is a valid month, then return # the name of the month with the first letter # capitalized. # months = ['January', 'February', 'March', 'April', 'May', 'June',

'July', 'August', 'September', 'October', 'November', 'December'] def valid_month(month): RedirecQon Instead of rendering the result in a post, we send them to another page that says "Thanks!". If the user's post is successful, the server sends a redirect message that causes the browser to get the "success" page. Why is it nice to redirect aeer a form submission?

So that reloading the page doesn't resubmit the form. So we can have disqnct pages for forms and success pages. ImplemenQng RedirecQon Let's make the change to our applicaqon. We need to: make a "thanks" handler. add the /thanks URL. redirect to the /thanks URL. handler for redirects class

ThanksHandler(webapp2.Re questhandler): def get(self) self.response.out.write( "Thanks! That's a totally valid day!") app = webapp2.wsgiapplication( [('/', MainPage), ('/thanks', ThanksHandler)], debug=true)

class MainPage(webapp2.Request Handler): def post(self): user_month = self.request.get('month' ) user_day = self.request.get('day') user_year = self.request.get('year') month = valid_month(user_month) day =

valid_day(user_day) year = valid_year(user_year) if not(month and day and year): self.write_form("that doesn't look valid to me, friend.", user_month, user_day, user_year) else: self.redirect("/thanks") Final Version of our ApplicaQon using ValidaQon

and Redirect import webapp2 import cgi def escape_html(s): return cgi.escape(s, quote = True) form = """ <form method="post"> What is your birthday? <br> <label> Month <input type="text" name="month" value="%

(month)s"> </label> <label> Day <input type="text" name="day" value="%(day)s"> </label> <label> Year <input type="text" name="year" value="%(year)s"> </label> <div style="color: red">% (error)s</div> <br><br> <input type="submit"> </form>

""" months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] def valid_day(day): if(day and day.isdigit()): day = int(day) if(day < 32 and day > 0): return day def valid_month(month): if(month):

month = month.capitalize() if(month in months): return month def valid_year(year): if(year and year.isdigit()): year = int(year) if(year < 2020 and year > 1880): return year class MainPage(webapp2.RequestHan dler): def write_form(self, error="", month="", day="", year=""):

self.response.out.write(form %{"error": error, "month": escape_html(month), "day": escape_html(day), "year": escape_html(year)}) def get(self): self.write_form() def post(self): user_month = self.request.get('month') user_day = self.request.get('day')

user_year = self.request.get('year') month = valid_month(user_month) day = valid_day(user_day) year = valid_year(user_year) if not(month and day and year): self.write_form("that doesn't look valid to me, friend.", user_month, user_day, user_year) else: self.redirect("/thanks")

class ThanksHandler(webapp2.Reques thandler): def get(self): self.response.out.write("thanks! That's a totally valid day!") app = webapp2.wsgiapplicaqon([('/', MainPage), ('/thanks', ThanksHandler)], debug=true) Homework for Problem Set 2

h?ps://www.udacity.com/ course/viewer#!/c-cs253/ l-48756009/e-48538417/ m-48696518