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

  • Home
  • SEARCH
  • 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 191469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:20:38+00:00 2026-05-11T16:20:38+00:00

I’m attempting my first google app engine project – a simple player stats database

  • 0

I’m attempting my first google app engine project – a simple player stats database for a sports team I’m involved with. Given this model:

class Player(db.Model):
    """ Represents a player in the club. """

    first_name = db.StringProperty()
    surname = db.StringProperty()
    gender = db.StringProperty()

I want to make a basic web interface for creating and modifying players. My code structure looks something like this:

class PlayersPage(webapp.RequestHandler):
    def get(self):
        # Get all the current players, and store the list.
        # We need to store the list so that we can update
        # if necessary in post().
        self.shown_players = list(Player.all())

        # omitted: html-building using django template

This code produces a very basic HTML page consisting of a form and a table. The table has one row for each Player, looking like something like this:

  <tr>
    <td><input type=text name="first_name0" value="Test"></td>
    <td><input type=text name="surname0" value="Guy"></td>
    <td><select name="gender0">
        <option value="Male" selected>Male</option>
        <option value="Female" >Female</option>
      </select></td>
  </tr>
  <!-- next row: first_name1, etc. -->

My idea is that I would store the Player instances that I used in self.shown_players, so that I could later update Players if necessary in my post() method (of the same class) by doing:

def post(self):
    # some code skipped

    for i, player in enumerate(self.shown_players):
        fn = self.request.get('first_name'+str(i)).strip()
        sn = self.request.get('surname'+str(i)).strip()
        gd = self.request.get('gender'+str(i)).strip()
        if any([fn != player.first_name,
                sn != player.surname,
                gd != player.gender]):
            player.first_name = fn
            player.surname = sn
            player.gender = gd
            player.put()

However, this doesn’t work because self.shown_players does not exist when the post() method is called. I guess the app engine creates a new instance of the class every time the page is accessed.

I experimented with the same idea but putting shown_players at the class or module level (and calling it global) but this didn’t work for reasons that I cannot divine.
For example:

shown_players = []
class PlayersPage(webapp.RequestHandler):
    def get(self):
        # Get all the current players, and store the list.
        # We need to store the list so that we can update
        # if necessary in post().
        global shown_players
        shown_players[:] = list(Player.all())

shown_players appears to have the right value within get() because the HTML generates correctly, but it is empty within post().

What should I do?

EDIT: Thanks, all. The answer (“Just retrieve the players again!”) should have been obvious 🙂 Maybe I’ll look at memcache one day, but I’m not expecting the player list to get beyond 30 in the near future..

  • 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-11T16:20:39+00:00Added an answer on May 11, 2026 at 4:20 pm

    On each request you are working on a new instance of the same class. That’s why you can’t create a varable in get() and use its value in post(). What you could do is either retrieve the values again in your post()-method or store the data in the memcache.

    Refer to the documentation of memcache here:

    http://code.google.com/intl/de-DE/appengine/docs/python/memcache/

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

Sidebar

Ask A Question

Stats

  • Questions 214k
  • Answers 214k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you on .NET 3.5 ? If so, go check… May 12, 2026 at 10:46 pm
  • Editorial Team
    Editorial Team added an answer You would need to do a client-side hash of the… May 12, 2026 at 10:46 pm
  • Editorial Team
    Editorial Team added an answer The complexity of cartesian product is O(n2), there is no… May 12, 2026 at 10:46 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
In order to apply a triggered animation to all ToolTip s in my app,
I have a French site that I want to parse, but am running into

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.