Tring to assign a value via constructor. but getting "TypeError: 'NoneType' object does not support item assignment".
import webapp2
from google.appengine.ext import ndb
class test(ndb.Model):
status = ndb.StringProperty(default=None)
def __init__(self):
self.status = "Test Status"
class MainPage(webapp2.RequestHandler):
def get(self):
a = test()
a.put()
app = webapp2.WSGIApplication([('/', MainPage)], debug=True)
Error:
File "/home/user/Appengine/guestbook/guestbook.py", line 15, in get
a = test()
File "/home/user/Appengine/guestbook/guestbook.py", line 10, in __init__
self.status = "Test Status"
File "/home/user/google_appengine/google/appengine/ext/ndb/model.py", line 1265, in __set__
self._set_value(entity, value)
File "/home/user/google_appengine/google/appengine/ext/ndb/model.py", line 1011, in _set_value
self._store_value(entity, value)
File "/home/user/google_appengine/google/appengine/ext/ndb/model.py", line 992, in _store_value
entity._values[self._name] = value
TypeError: 'NoneType' object does not support item assignment
You probably need to initialize the
ndb.Model
properly by calling its__init__
: