Take the 2-minute tour ×

I'm new to GAE and Web Programming in general so please bare with me!

I have a question:

Is it possible to create a textbox in HTML, type a string into it, click a "save" button, store that information onto a GAE datastore model and have the text stay displayed in the textbox and saved in the datastore?

The HTML is on a separate file, just rendered through my main.py file using

class MainPage(webapp.RequestHandler):
def get(self):

    template_values = {}
    self.response.out.write(template.render(path, template_values))

What I tried for my problem is this:

class equipmentBox(db.Model):
    equipCode = db.StringProperty()

class equipmentBoxGet(webapp.RequestHandler):
    def post(self):

Thanks so much in advance!

share|improve this question
there is tag called google-app-engine here, make sure next time you are posting your question in the right place.. –  Abdul Kader May 26 '11 at 4:56
sorry about that. thanks for the tip! –  todazar May 26 '11 at 13:51

2 Answers 2

up vote 3 down vote accepted

I think this will help, i have modified default guestbook app for you. Usual way of doing is having html files separately and using templates to render it. Here everything is just embedded into the controller itself

import cgi

from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db

class EquipmentBox(db.Model):
      equipCode = db.StringProperty()

class MainPage(webapp.RequestHandler):
  def get(self):

    equips = db.GqlQuery("SELECT * FROM EquipmentBox")

    for equip in equips:


    # Write the submission form and the footer of the page
            <div><input type="text" name="equip_code" /></div>
            <div><input type="submit" value="post equipcode"></div>

class EquipBox(webapp.RequestHandler):
  def post(self):
    equip = EquipmentBox()
    equip.equipCode = self.request.get('equip_code')

application = webapp.WSGIApplication(
                                     [('/', MainPage),
                                      ('/post', EquipBox)],

def main():

if __name__ == "__main__":
share|improve this answer
Thanks for the reply. The problem I have is that I need to display the string in a textbox. You nicely put the string enclosed in blockquote markup but is it possible to put that into a textbox? –  todazar May 26 '11 at 17:33
Use <textarea>%s</textarea> instead of <blockquote>%s</blockquote> –  Drew Sears May 26 '11 at 17:37
Of course, it is possible . Just Drew suggested change <blockquote> to <textarea> –  Abdul Kader May 27 '11 at 5:06

The best way to build this sort of interface, where the user "saves" data on the page without the page changing, is to use AJAX calls.

While a full explanation of how AJAX works is probably beyond the scope of an answer here, the basic idea is that you have a Javascript onclick event attached to your Save button, which sends the contents of your textbox via a POST request to the server. See the link above for a tutorial.

share|improve this answer

Your Answer


