1

I'm using Jinja2 and Google App Engine.

I identify my models with integer num:

class TestModel(db.Model):
    value = db.StringProperty()
    num = db.IntegerProperty()

and have a class for editing the value:

class Edit(Handler):
    def get(self):
        #show input box with value, let user edit value, render page with num


    def post(self):
        #get new value, filter database for model instance BY NUM and replace with new value

I need to store num on the page so I can retrieve it for the post method but I don't want the page to display it.

I tried:

<span name = "num" value = "{{num}}"></span>

and in the post method I have

 num = self.request.get('num')
 logging.error("NUM: %s" % num)

But when I run this, num doesn't show in the logs (I have "NUM: ") and I get

ValueError: invalid literal for int() with base 10: ''

When I render the page, the source code shows that num is there. Why isn't this code properly retrieving num?

1 Answer 1

4

Have you tried putting the field into a hidden input element. i.e.

<input type="hidden" name="..." value="..."/>

Also make sure that the value you are trying to retrieve in your post is within the form tags.

1
  • That was it, thank you. Why does the input tag work and not the span tag?
    – mango
    Jan 15, 2014 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.