Read each line of HTML form submission Python
I'm building a small web app with Python on GAE.
I have an HTML form with a where users enter a list of items (one item per line). When the form is submitted I want to read each line and store separa开发者_高级运维te entries in the datastore for each item (i.e. line).
I want to do something similar to f.readline() for files, but on the form submission. It's entirely possible that this is incredibly easy. I'm a complete noob so any help you be greatly appreciated.
Sounds like you want (have?) a text area control in your form, like the one I'm typing into now. Something like this?
<textarea name="items"></textarea>
When handling the POST request for the form, you will be able to get the value of the text area like so.
itemList = self.request.get("items")
It will post back the entire text with newline characters (with the escape code \n). The text can be split into a list of lines.
items = itemList.split("\n")
Aaaand you have a list of lines.
精彩评论