Re: [問題] GAE的DataStore

看板Python作者 (請吱解我)時間14年前 (2010/12/26 12:14), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串4/4 (看更多)
※ 引述《hchungi (8165)》之銘言: (略) : from google.appengine.ext.webapp import template : from google.appengine.ext.webapp.util import run_wsgi_app : from google.appengine.ext import db : class Project(db.Model): : ProjectId = db.StringProperty(required=True) : ProjectName = db.StringProperty(required=True) : class MainPage(webapp.RequestHandler): : def get(self): : path = os.path.join(os.path.dirname(__file__), 'Default.html') : self.response.out.write(template.render(path, [])) : class PutDataStore(webapp.RequestHandler): : def post(self): : #self.response.out.write("<script>alert('"+self.request.get("txtProjectId")+"');</script>") : proj = Project(self.request.get("txtProjectId")) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ proj = Project(ProjectId=self.request.get("txtProjectId")) 或 proj = Project() proj.ProjectId=self.request.get("txtProjectId") 沒測試過 不過應該是這個問題 如果你的ProjectId是不重複的 可以設一下利用ProjectId當作key_name 以後取值比較容易 : proj.ProjectName = self.request.get("txtProjectName") : proj.put() : self.response.out.write("<script>alert('OK');</script>") : application = webapp.WSGIApplication( : [('/',MainPage), : ('/putDB', PutDataStore)], : debug=True : ) : def main(): : run_wsgi_app(application) : if __name__ == "__main__": : main() : [Default.html] : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" : "" rel="nofollow">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> : <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> : <head></head> : <html> : <body> : <form action="/putDB" method="post"> : <span>1234567</span> : <br /> : <span>Project ID:</span><input type='text' name='txtProjectId' /><br/> : <span>Project Name:</span><input type='text' name='txtProjectName' /><br/> : <input type='submit' value='Save' /> : </form> : </body> : </html> -- ┌────*.──────個時真的DJ享受不同聽覺┌╮ *╭─╮* *。 。│*.==電台網址== http://s-radio.whyza.net:8000/ ╰┘ *.│ ==使用方法== 請點子電台 Diva Project 即可收聽 **╰─ ==ShineRadio電台== 歡迎你來收聽 ╭┐* │。 ┼─。────────────────────────┘└╯╯○ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.193.15.63
文章代碼(AID): #1D5i4_Tn (Python)
討論串 (同標題文章)
文章代碼(AID): #1D5i4_Tn (Python)