[問題] GAE的DataStore
各位Pyhton高手好
我最近在測試GAE的程式開發,我使用Google提供的Google App Engine Launcher做測試
我寫了一個簡單的DB Model類別存放數據
但無論我將檔案上傳到GAE或用GAE Launcher測試,都出現了下面這個錯誤訊息
Traceback (most recent call last):
File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 517, in __call__
handler.post(*groups)
File "D:\Regalscan\DevProject\PyProjects\rgsz\Default.py", line 20, in post
proj = Project(self.request.get("txtProjectId"))
File "C:\Program Files\Google\google_appengine\google\appengine\ext\db\__init__.py", line 770, in __init__
(parent, parent.__class__.__name__))
TypeError: Expected Model type; received 123 (is unicode)
我找了好久都不知道錯在哪,網路上似乎也沒有相關資料
所以請有用過GAE的高手指教一下,以下是我的程式碼,謝謝
[Default.py]
import os
from google.appengine.ext import webapp
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.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>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.218.0.13
討論串 (同標題文章)
Python 近期熱門文章
PTT數位生活區 即時熱門文章