문제

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 separate 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top