我写了这个简单的输入用户名并保存到数据存储。但我面临的问题是,每次重新加载结果页面时("欢迎用户"),相同的用户名将再次存储在具有不同密钥的数据存储区中。如何在重新加载时阻止用户名存储到数据存储区?
import webapp2
from google.appengine.ext import db
#form is a simple html file which takes an input.
class Name(db.Model):
username = db.StringProperty(required=True)
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.out.write(form)
def post(self):
username = self.request.get('username')
self.response.out.write("Welcome"+str(username))
user1 = Name(username=username)
user1.put()
application = webapp2.WSGIApplication([
('/', MainHandler)
], debug=True)
PS:请原谅我以下评论!