i have an aplication that takes some parameters through an html form and then creates a model entity. The problem is, that whatever i try, i get an error like this:
BadValueError: Property xxx must be a list
this is the model:
xxx = db.ListProperty(int)
this is the sentence used for getting the list:
xxx = self.request.get('xxx')
I figure that the html form returns a string as i hit the submit button. So, how would i be able to get a list from an input type="text" in an html form? If i write 1,2 it's not ok, as isn't anything else.
The python code is similar to the helloworld application where a form is used to post greetings on the page, the difference is that i need to get a list, not text.
self.response.out.write("""
<form action="/sign" method="post">
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="submit" value="Sign Guestbook"></div>
</form>
</body>
</html>""")
class Guestbook(webapp.RequestHandler):
def post(self):
greeting = Greeting()
if users.get_current_user():
greeting.author = users.get_current_user()
greeting.content = self.request.get('content')
greeting.put()
self.redirect('/')
Is this the optimal way to get user input to create a model entity and how can i fix it so that it will get a list and write it in the models attributes?
You should put lists inside
xxx
, not strings or integers.Maybe you would want to use request.get_all method, instead of get.