Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 289697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:55:50+00:00 2026-05-12T05:55:50+00:00

Ok, you guys were quick and helpful last time so I’m going back to

  • 0

Ok, you guys were quick and helpful last time so I’m going back to the well 😉

Disclaimer: I’m new to python and very new to App Engine. What I’m trying to do is a simple modification of the example from the AppEngine tutorial.

I’ve got my date value being stored in my Memory class:

class Memory(db.Model):
    author = db.UserProperty()
    content = db.StringProperty(multiline=True)
    date = db.DateProperty(auto_now_add=True)

and now I want to be able to lookup records for a certain date. I wasn’t sure exactly how to do it so I tried a few things including:

memories = db.GqlQuery("SELECT * from Memory where date = '2007-07-20')
and
memories = Memory.all()
memories.filter("date=", datetime.strptime(self.request.get('date'), '%Y-%m-%d').date())
and
memories = Memory.all()
memories.filter("date=", self.request.get('date'))

But every time I run it, I get an ImportError. Frankly, I’m not even sure how to parse these error message I get when the app fails but I’d just be happy to be able to look up the Memory records for a certain date.

EDIT: FULL SOURCE BELOW

import cgi
import time

from datetime import datetime
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 Memory(db.Model):
    author = db.UserProperty()
    content = db.StringProperty(multiline=True)
    date = db.DateProperty()

class MainPage(webapp.RequestHandler):
    def get(self):
        self.response.out.write('<html><body>')

        memories = db.GqlQuery('SELECT * from Memory ORDER BY date DESC LIMIT 10')

        for memory in memories:
            self.response.out.write('<b>%s</b> wrote: ' % memory.author.nickname())
            self.response.out.write('<em>%s</em>' % memory.date)
            self.response.out.write('<blockquote>%s</blockquote>' % cgi.escape(memory.content))

        self.response.out.write("""
<div style="float: left;">
<form action="/post" method="post">
    <fieldset>
    <legend>Record</legend>
    <div><label>Memory:</label><input type="text" name="content" /></textarea></div>
    <div><label>Date:</label><input type="text" name="date" /></div>
    <div><input type="submit" value="Record memory" /></div>
    </fieldset>
</form>
</div>
<div style="float: left;">
<form action="/lookup" method="post">
    <fieldset>
    <legend>Lookup</legend>
    <div><label>Date:</label><input type="text" name="date" /></div>
    <div><input type="submit" value="Lookup memory" /></div>
    </fieldset>
</form>
</div>""")

        self.response.out.write('</body></html>')

class PostMemory(webapp.RequestHandler):
    def post(self):
        memory = Memory()

        if users.get_current_user():
            memory.author = users.get_current_user()

        memory.content = self.request.get('content')
        memory.date = datetime.strptime(self.request.get('date'), '%Y-%m-%d').date()

        memory.put()
        self.redirect('/')

class LookupMemory(webapp.RequestHandler):
    def post(self):
        memories = db.GqlQuery("SELECT * FROM Memory WHERE date = '2009-07-21'")

        for memory in memories:
            self.response.out.write('<b>%s</b> wrote: ' % memory.author.nickname())
            self.response.out.write('<em>%s</em>' % memory.date)
            self.response.out.write('<blockquote>%s</blockquote>' % cgi.escape(memory.content))     

application = webapp.WSGIApplication([('/', MainPage), ('/post', PostMemory), ('/lookup', LookupMemory)], debug=True)

def main():
    run_wsgi_app(application)

if __name__ == '__main__':
    main()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:55:50+00:00Added an answer on May 12, 2026 at 5:55 am
    class Memory(db.Model):
        author = db.UserProperty()
        content = db.StringProperty(multiline=True)
        date = db.DateProperty(auto_now_add=True)
    

    I think that you are either getting import errors for memory or your are getting an import error for datetime

    if Memory is in another .py file, e.g otherpyfile.py, you will need to do from otherpyfile import Memory and then use it that way

    if its a datetime issue then you will need to import datetime. Your first answer had a mismatch of quotes so sorted that. I sorted your middle one so that if you import datetime

    memories = db.GqlQuery("SELECT * from Memory where date = '2007-07-20'")
    
    memories = Memory.all().filter("date=", datetime.datetime.strptime(self.request.get('date'), '%Y-%m-%d').date())
    
    memories = Memory.all().filter("date=", self.request.get('date'))
    

    The appengine error screen isn’t always helpful so have a look at the logs that are being thrown in the command prompt. If you see that error it might be worth dumping the short stacktrace it does so I can try help you further.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just a quick question guys, how can I simulate a tap on the back
Hey guys, quick question, just trying to filter a user's first and last name
Hey guys quick question, I have an entry that I put in my database,
Hey guys quick question, I currently have an insert statement $query= INSERT into new_mail
Hey guys quick question. I have a div that gets assigned a number to
Hey guys quick question, I want to update the contents of a div with
Hey guys got a quick question here, how do i set up TweetStream after
Hey guys, one more quick question for any experts out there. I have a
Hey guys, quick question for any experts out there. I am allowing users to
Hey guys quick question, I am currently echoing a lot of javascript that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.