作者hchungi (8165)
看板Python
标题[问题] GAE的DataStore
时间Sun Dec 26 00:11:58 2010
各位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"
"
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