views:

41

answers:

1

I'm stuck with this problem I made an HTML Array, but I can't read it out with Python. Is it even possible to do it in App Engine? I read it was possible in PHP.

This is the html code:

<label for="hashtags">Hashtags: </label><br/>
{% for hashtag in stream.hashtags %}
    <input type="text" value="{{hashtag}}" name="hashtags[]" id="hashtags" class="text ui-widget-content ui-corner-all" />
{% endfor %}

This is how I'm currently trying to read the HTML Array:

newHashTags = self.request.get('hashtags[]')
for newHashTag in newHashTags:
    stream.hashtags.append(newHashTag)

This is in the post variable when I'm debugging.

MultiDict: MultiDict([('streamid', '84'), ('name', 'Akteurs'), ('description', '#stream'), ('hashtags[]', '#andretest'), ('hashtags[]', '#saab')])
+4  A: 

You don't need to include the [] at the end of the name of a field you'd like to treat as a list or array, that's some PHP-specific magic. Instead, just name the field hashtags and in your request handler do this to get a list of hashtags from the request:

newHashTags = self.request.get('hashtags', allow_multiple=True)

The allow_multiple=True argument will make get method return a list of all hashtags values in the request. See the relevant documentation for more info.

You could also avoid the for loop by doing something like this:

newHashTags = self.request.get('hashtags', allow_multiple=True)
stream.hashtags.extend(newHashTags)
Will McCutchen
Perfect answer. Thanks.
Sam S