[vagrant@localhost]$ sudo yum -y install telnet Trying 35.160.185.106... Connected to www.udacity.com. Escape character is '^]'. GET / HTTP/1.0 Host: www.example.com HTTP/1.1 302 Found Cache-Control: no-cache Location: https://www.example.com/ Content-Length: 0 Connection: Close
input form
<form action="http://www.google.com/search"> <input name="q"> <input type="submit"> </form>
play.py
import webapp2 class MainPage(webapp2.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('Hello, webapp World!') app = webapp2.WSGIApplication([('/', MainPage)], debug=True)
ダブルクォーテーション3つでくくると、複数行に渡る文字列を記述することができる。
import webapp2 form=""" <form action="http://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('Hello, webapp World!') app = webapp2.WSGIApplication([('/', MainPage)], debug=True)
form parameter
<form> <input type="radio" name="q" value="one"> <input type="radio" name="q" value="two"> <input type="radio" name="q" value="third"> <br> <input type="submit"> </form>
<form> <label> one <input typ\e="radio" name="q" value="one"> </label> <label> two <input type="radio" name="q" value="two"> </label> <label> three <input type="radio" name="q" value="third"> </label> <br> <input type="submit"> </form>
select
<form> <select name="q"> <option value="1">the number one</option> <option>two</option> <option>three</option> </select> <br> <input type="submit"> </form>
User validation
import webapp2 form=""" <form method="post"> What is your birthday? <br> <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> <br> <input type="submit"> </form> """ class MainPage(webapp2.RequestHandler): def get(self): self.response.out.write(form) def post(self): self.response.out.write("Thanks! That's a totally valid day!") app = webapp2.WSGIApplication([('/', MainPage),('/testform', TestHandler)], debug=True)