Saturday, 15 February 2014

Google App engine: No key_name attribute -



Google App engine: No key_name attribute -

i'm trying larn how gae, things working, unusual reason, code outputs

attributeerror: 'user_account' object has no attribute 'key_name'

here's 2 code extracts relevant:

class user_account(ndb.model): name = ndb.stringproperty() firstname = ndb.stringproperty() class adduser(webapp2.requesthandler): def get(self): test_user = user_account(name = "snow", firstname ="jon", key_name="jon")

i've tried db , ndb model, doesn't work either way...

thanks in advance answer.

update: here's "full" code (i removed other un-necessary parts):

import webapp2 import cgi google.appengine.ext import ndb main_page_html = """\ <html> <body> <br/> <a href="/add_user"> add together user </a> </body> </html> """ class comment(ndb.model): content = ndb.stringproperty() class user_account(ndb.model): name = ndb.stringproperty() firstname = ndb.stringproperty() comments = ndb.keyproperty(repeated=true) class adduser(webapp2.requesthandler): def get(self): test_user = user_account(name = "jon", firstname ="snow", key_name="jon") self.response.write(test_user.key_name + "<br/>") test_user.put() self.response.write("user added") class mainpage(webapp2.requesthandler): def get(self): self.response.write(main_page_html) application = webapp2.wsgiapplication([ ('/', mainpage), ('/add_user', adduser) ], debug=true)

moar edit: simple code, when executed in dev console, outputs error

import os import pprint google.appengine.ext import ndb class comment(ndb.model): content = ndb.stringproperty() test_comment = comment(content="hello world", key_name="hello") test_comment.put()

please read documentation ndb model class. on model constructor arguments. https://developers.google.com/appengine/docs/python/ndb/modelclass#constructor

you see takes id, rather than key_name. key_name constructor argument db api.

google-app-engine google-datastore

No comments:

Post a Comment