0
我遇到了我的項目問題。我有2種型號Appengine - 如何獲取實體並顯示值
class UserPrefs(db.Model):
user = db.UserProperty()
name = db.StringProperty()
class Person(db.Model):
name = db.StringProperty()
phone = db.PhoneNumberProperty()
userPrefs = db.ReferenceProperty(UserPrefs)
class PersonHandler(webapp.RequestHandler):
def get(self):
users.get_current_user user =()
if user:
greeting = ......
else:
greeting = ......
if self.request.GET.has_key ('id'):
id = int (self.request.get ['id'])
person = models.Person.get = (db.Key.from_path ('Person', id))
path = os.path.join (os.path.dirname (__file__), 'templates/doStuff.html')
self.response.out.write (template.render (path, locals(), debug = True))
def post (self):
if self.request.get ('Person'):
id = int (self.request.get ('Person'))
person = models.Person.get (db.Key.from_path ('Person', id))
else:
person= models.Person =()
data = forms.PersonForm date = (data = self.request.POST)
if data.is_valid():
if self.request.get ('photo'):
Person.foto db.Blob = (self.request.get ('photo'))
person.nome self.request.get = ('name')
person.apelido self.request.get = ('name')
person.unidade self.request.get = ('unit')
person.put()
self.redirect ('/ doSomeStuff')
else:
self.redirect ('doOtherStuff')
To See the data in database i use this handler:
class SeePersonHandler (webapp.RequestHandler):
def get (self):
users.get_current_user user =()
if user:
greeting = ......
else:
greeting = ......
person= db.Query(models.Pocente)
persons = person.fetch(limit = 1)
path = os.path.join(os.path.dirname(__file__), 'templates/SeeStuff.html')
self.response.out.write(template.render(path, locals(), debug = True))
問題: 我知道數據放在corectly。我使用SDK控制檯的這個網址:http://localhost:8080/_ah/admin/datastore,實體創建正確。我不知道我缺少檢索dadta已經把
我的模板:
{% if user %}
{% if person%}
<table align="center">
<tbody>
<tr>
<td><input type="button" value="Criar Pessoa" onclick="redirect(3)" /></td>
</tr>
</tbody>
</table>
<table align="center">
<tbody>
<tr>
<td colspan="2"><center><strong><p>O meu Curriculum Vitae</p></strong></center></td>
</tr>
<tr>
<td>Nome: </td>
<td>{{ person.name}}</td>
</tr>
<tr>
<td>Apelido: </td>
<td>{{ person.phone}}</td>
</tr>
<tr>
<td></td>
<td>
<input type ="button" value="Editar" onclick="editarCv({{ person.key.id }})" />
</td>
</tr>
</tbody>
</table>
{% endif %}
{% endif %}
感謝亞當。有效。現在,當我嘗試編輯信息時,出現以下錯誤:文件「C:\ Users \ hp \ workspace \ AnApp \ src \ main.py」,第173行,獲取 id = int(self.request.get [ 'id']) TypeError:'instancemethod'對象不可訂閱 – 2010-09-17 09:24:37
奇怪的是,該錯誤反映了我用來放置信息的處理程序:if self.request.GET.has_key('id'): id = int(self.request.get ['id']) list_Person = models.Person.get(db.Key.from_path('Person',id)) – 2010-09-17 09:27:46
對不起,請教這個問題。我很笨。我的錯誤是獲取而不是GET。 – 2010-09-17 10:20:46