Anda di halaman 1dari 9

How the web Works Html makrup: Tags: <name>Contents</name> <b>Contents</b> Pone en negrilla el contenido. <em>Contents</em> emphasis, italic.

Html attributes <tag ATTR=value> contents</tag> estructura de un tag <a href=www.reddit.com>derp</a> link Adding images <img src=url alt=text> <img src="http://www.udacity.com/cs253x/hipmunk.png" alt="hipmunk!"> whitespace <br> break. (cambio de lnea) <p> contents </p>paragraph Span/div <span class=foo> <div class=bar> text text </span> </div> inline block Document structure HTML documents <!DOCTYPE HTML> -doctype <html> -html5 <head> head meta-data css javascript <title> Title!</title> </head> <body> <b> Contents </b> </body> </html>

Introducing URLs Protocol host path https://www.udacity.com/course/viewer#!/c-cs253/l-48737165/m-48701404 Query parameters http: //example.com/foo?p=1&q=neat Fragments http: //example.com/foo?p=1&q=neat#fragments Port http: //localhost:8080/ Get http://www.example.com/foo Method path version GET /foo http/1.1 - request line Making request http request GET /foo?p=1 HTTP/1.1 Host: www.example.com User-agent: chrome v.17 http responses HTTP/1.1 200 Status code OK reason phrase Headers: Name:value

Status codes: 200 ok 302 found 404 not found 500 server error Servers Purpose: Respond to http requests Two types of responses. Static (images) Dynamic (Web application)

Form
<form action ="http://www.google.com/search"> <input name="q" > <input type="submit"> </form> <form> <input type="password" name="q" > <input type="submit"> </form>

GET Y POST Get, para documentos y guardar en cach. (longitud mxima de URL) Post, para recargar pginas, no lenght max de url. No aparecen las solicitudes en la URL. Checkboxes
<form> <input type="checkbox" name="q" > <input type="checkbox" name="r" > <input type="checkbox" name="s" > <br> <input type="submit"> </form> Radio <form> <input type="radio" name="r" value="one"> <input type="radio" name="r" value="two"> <input type="radio" name="r" value="three"> <br> <input type="submit"> </form>

Label
<form> <label> One <input type="radio" name="r" value="one"> </label> <label>

Two <input type="radio" name="r" value="two"> </label> <label> Three <input type="radio" name="r" value="three"> </label> <br> <input type="submit"> </form> Dropdowns //Si no hay value, q va a tomar el texto que hay dentro de los elementos. <form> <select name="q"> <option value="1">one</option> <option>two</option> <option>three</option> </select> <br> <input type="submit"> </form>

Validation 1) verify the users input 2) On error, render form again 3) Include error message

Python //////////////// def valid_day(day): try: i=int(day) except ValueError: return if int(day) >= 1 and int(day) <= 31 :

return int(day) /////////////// def valid_month(month): if(month): monthc=month.capitalize() if monthc in months: return monthc ///////////////////// print valid_month("January") //////////////////

/////////////////////

////////////////////////// def valid_year(year): if year and year.isdigit():

year=int(year) if year<=2020 and year>=1900: return year print valid_year('1900') ////////////////

import webapp2 months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] def valid_year(year): if year and year.isdigit(): year=int(year) if year<=2020 and year>=1900: return year

def valid_month(month): if(month): monthc=month.capitalize() if monthc in months: return monthc def valid_day(day): try: i=int(day) except ValueError: return if int(day) >= 1 and int(day) <= 31 : return int(day)

form=""" <form method="post">

What is your birthday? <label> Month <input type="text" name="month"> </label> <label> Day <input type="text" name="day"> </label> <label> Year <input type="text" name="year"> </label> <br> <input type="submit"> </form> """ class MainPage(webapp2.RequestHandler): def get(self): #self.response.headers['Content-Type']='text/plain' self.response.write(form) def post(self): #self.response.headers['Content-Type']='text/plain' #self.response.write(form) 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.write(form) else: self.response.write("Nice!, that is a valid date. Thank you :)") #self.response.write(hola()) #class TestHandler(webapp2.RequestHandler): # def post(self): #self.response.headers['Content-Type']='text/plain' #q=self.request.get("q"); #self.response.out.write(q) # self.response.headers['Content-Type']='text/plain' # self.response.out.write(self.request) #<form method="post" action="/testform"> #,('/testform',TestHandler)

app = webapp2.WSGIApplication([ ('/', MainPage) ], debug=True)

////////////////////////////////// given_string = "I think %s is a perfectly normal thing to do in public." def sub1(s): return given_string % s print sub1("running") # sub1("running") # => "I think running is a perfectly normal thing to do in public." # sub1("sleeping") # => "I think sleeping is a perfectly normal thing to do in public." //////////////////////////// given_string2 = "I think %s and %s are perfectly normal things to do in public." def sub2(s1, s2): return given_string2 % (s1,s2) print sub2("running", "sleeping") # sub2("running", "sleeping") # => "I think running and sleeping are perfectly normal things to do in public." # sub2("sleeping", "running") # => "I think sleeping and running are perfectly normal things to do in public." ////////////////////////////////// # User Instructions # # Write a function 'sub_m' that takes a # name and a nickname, and returns a # string of the following format: # "I'm NICKNAME. My real name is NAME, but my friends call me NICKNAME." # given_string2 = "I'm %(nickname)s. My real name is %(name)s, but my friends call me %(nickname)s." def sub_m(name, nickname): return given_string2 % {"nickname":nickname, "name":name}

print sub_m("Mike", "Goose") # sub_m("Mike", "Goose") # => "I'm Goose. My real name is Mike, but my friends call me Goose." //////////////////////////

Anda mungkin juga menyukai