Question

My app, Datastore, webapp2, and form-specific "responses" are all working :) but I need the page to load without displaying previous visitor's query results. I need query results only for current form-submitter, after they submit form. Is this a session or headers solution, or can I edit the GqlQuery to accomplish this?

messages = db.GqlQuery("SELECT * "
                                "FROM Visitor " 
                                "ORDER BY date DESC LIMIT 1") #obviously shows previous form submit
        for message in messages:
            if message.name == "" or message.mood == "":
                self.response.out.write("<div class='textright'>Type name and select.</div>")
                self.response.out.write("</body></html>")
            elif message.mood == "bad" and message.name != "":
                self.response.out.write("<body><html>")
                self.response.out.write("<div class='textright'>Stay the course  

^ ^ this last section is my "response" that needs to appear only after current visitor submits form.

Was it helpful?

Solution

I would strongly recommend you to go through the Getting Started and especially the templates section, until you will understand how it works.

But you if you just want to see your example in action try this (read more):

class Process(webapp.RequestHandler):
  def post(self):
    name = self.request.get("name")
    mood = self.request.get("mood")

    if mood == "bad" and name != "": 
      self.response.out.write("<html><body>")
      self.response.out.write("<h1>Welcome to the Internet!</h1>")
      self.response.out.write("<p>My mood is %s and my name is %s</p>" % (mood, name))
      self.response.out.write("</body></html>")
    else:
      self.response.out.write("<html><body>")
      self.response.out.write("<h1>Welcome to the Internet anyway!</h1>")
      self.response.out.write("</body></html>")

Also never use print in your GAE applications, use the logger instead for debugging and more.

OTHER TIPS

If you want to emit values for debugging purposes, particularly if you want that before an <html> tag is written, try

self.response.out.write("<!-- name: %s -->" % self.request.get("name"))

Otherwise, the browser might get confused.

print from a handler will never to what you expect.

In your snippet, you haven't shown where var7 and var9 come from.

I do realize that post/.put form values to Datastore automatically redirects user to new page

I think you misunderstand. You haven't shown us where your code does a put() or a redirect. A post() handler does not automatically do either.

Which tutorial are you looking at? Perhaps we need to tighten up vague wording.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top