Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle App Engine datastore model property returns none
    primarykey
    data
    text
    <p>I am trying to create a basic use of the Google App Engine's datastore and db model. My model object is </p> <pre><code>class Table(db.Model): row = db.IntegerProperty() col = db.IntegerProperty() date = db.DateTimeProperty(auto_now_add=True) </code></pre> <p>it will be used to just hold a table of rows and columns. User gives input via html, and then I save the table and draw all of the tables in the datastore. I use <code>Table.all()</code> to get all tables from the datastore and then try to access their contents so that I can print the table but for some reason when table.row and table.col is read in <code>for y in range(row):</code> will apparently return a noneType, does anyone know why?</p> <pre><code>import webapp2 from google.appengine.ext.webapp.util import run_wsgi_app from google.appengine.ext import db from logging import error INITIAL_INPUT = """\ &lt;html&gt; &lt;body&gt; &lt;form action="/out?%s" method="POST"&gt; &lt;input type="text" name="row" /&gt; &lt;input type="text" name="col" /&gt; &lt;input type="submit" value="Submit" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; """ class Table(db.Model): """Models an individual Guestbook entry with author, content, and date.""" row = db.IntegerProperty() col = db.IntegerProperty() date = db.DateTimeProperty(auto_now_add=True) class MainPage(webapp2.RequestHandler): def get(self): self.response.write(INITIAL_INPUT) class Out(webapp2.RequestHandler): def post(self): newRow = self.request.POST['row'] newCol = self.request.POST['col'] newTable = Table() newTable.row = int(newRow) if newRow else 1 newTable.col = int(newCol) if newCol else 1 newTable.put() tables = Table.all() for table in tables: self.drawTable(table.row, table.col) def drawTable(self, row , col): write = self.response.write write("&lt;html&gt;&lt;body&gt;&lt;table&gt;") for y in range(row): write("&lt;tr&gt;") for x in range(col): cell = "&lt;td bgcolor=\"#00FF00\"&gt;" + str(x) + " " + str(y) + "&lt;/td&gt;" if x % 2 == 0: cell = "&lt;td bgcolor=\"#FF0000\"&gt;" + str(x) + " " + str(y) + "&lt;/td&gt;" write(cell) write("&lt;/tr&gt;") write("&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;") application = webapp2.WSGIApplication([ ('/', MainPage), ('/out', Out)] , debug=True) def main(*args, **kwds): run_wsgi_app(application) if __name__ == "__main__": main() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload