【发布时间】:2014-11-06 08:52:57
【问题描述】:
在下面的代码中,我想在按下提交按钮时将文本留在表单中。目前按下提交时文本会消失。
这是我一直关注的教程链接: https://www.udacity.com/course/viewer#!/c-cs253/l-48736183/e-48754026/m-48717294
import webapp2
form = """
<!DOCTYPE html>
<head>
<title>Unit 2 Rot 13</title>
</head>
<body>
<h2>Enter some text to ROT13:</h2>
<form method = "post">
<textarea name="text" value="%(word)s" style="height: 100px; width: 400px;"></textarea>
<br>
<input type="submit">
</form>
</body>
</html>
"""
class MainHandler(webapp2.RequestHandler):
def write_form(self, word=""):
self.response.out.write(form % {"word": word})
def get(self):
self.write_form()
def post(self):
string = self.request.get("word")
self.write_form(string)
app = webapp2.WSGIApplication([('/', MainHandler),
], debug=True)
【问题讨论】: