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 6537303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:36:02+00:00 2026-05-25T10:36:02+00:00

I’m doing my first small project in Python(GAE), and there’s no difficulty in operating

  • 0

I’m doing my first small project in Python(GAE), and there’s no difficulty in operating GAE’s database using queries. But when it comes to editing single Entity I face a problem.
All I need is a simple counter which would increment on every site visit.
So I create an Entity (this is done once, just to create Entity, then this code is removed from project) by:

counter_name = 'default_counter'

def counter_key(counter_n=None):
   return db.Key.from_path('Counter', counter_name)

class Counter(db.Model):
    amount = db.IntegerProperty()

class CounterClass(webapp.RequestHandler):
    def get(self):
        counter = Counter(counter_key(counter_name))
        counter.amount = 0
        counter.put()

It is ok.
But when I try to increment it, using:

counter = db.get(db.Key.from_path('Counter', 'default_counter'))
counter.amount += 1
counter.put()

I get this Error.

ERROR 2011-09-06 21:49:41,562 _webapp25.py:464] ‘NoneType’ object
has no attribute ‘amount’ Traceback (most recent call last): File
“C:\Program Files
(x86)\Google\google_appengine\google\appengine\ext\webapp_webapp25.py”,
line 703, in call
handler.post(*groups) File
“H:\gae-bin\counter.py”, line
48, in post
counter.amount += 1 AttributeError: ‘NoneType’ object has no
attribute ‘amount’

I checked different variations, but still cant change Entity’s value.
What am I doing wrong?

Thanks in advance.

  • 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-25T10:36:03+00:00Added an answer on May 25, 2026 at 10:36 am

    The code you use to create the Counter entity is likely wrong. What it does is creating a Counter entity whose parent is Counter with keyname equal to default_counter. That doesn’t seem to be what your want, as evidenced by code you use to update the counter.

    You need to assign the keyname of your Counter entity via one of the following ways:

    counter = Counter(key_name='default_counter')
    # or
    counter = Counter(key=db.Key.from_path('Counter', 'default_counter'))
    

    Note that in general it is bad idea to have a visit counter like that. GAE entities have a limti for 5 updates per seconds so if you ever scale beyond that, you will run into problems.

    Common technique for dealing with the update limitation is to use sharding counters as described here: http://code.google.com/intl/pl/appengine/articles/sharding_counters.html . A combination of datastore and memcache is also an option if you don’t mind occasionally losing some counter increments.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.