Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simplest way to store a value in Google App Engine Python?

I'm lazy! And I just want to store one single string value. That's all! Can I jump over any kind of Modeling and just store a value?

like image 675
themirror Avatar asked Dec 02 '22 06:12

themirror


1 Answers

Not as far as I know: the DataStore is the only storage available on App Engine. However, it's not a lot of code, even if you are lazy. ;)

Make sure you import the db module:

from google.appengine.ext import db

Then just store a key/value pair (you can then use this model to store any other miscellaneous strings you might add as well):

class MyData(db.Model):
    myKey = db.StringProperty(required=True)
    myValue = db.StringProperty(required=True)

data = MyData(myKey="Title", myStringValue="My App Engine Application")
data.put()

You can get it again with:

db.Query(Entry).filter("myKey=", "Title").get().myStringValue
like image 198
Mark Bell Avatar answered Mar 02 '23 18:03

Mark Bell