2

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')])

1 Answer 1

5

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.