我想弄清楚如何分離數據,我將顯示在來自python中的元組的HTML頁面上。如何用換行符分隔數據
的Python:
callComments = (interface.list_comments(db,10))
content = { comments': '<p>%s</p>' % commentString,
}
HTML:
<div class = "comments">
<p>These are some comments:</p>
%comments
</div>
有這樣的輸出:
(13, '[email protected]', 'hello', ' amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut\nlabore et dolore magna aliqua. Ut') (12, '[email protected]', 'hello', 'orem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor i') (11, '[email protected]', 'hello', 'consectetur adipisicing elit, sed do eiusmod tempor incididunt ut\nlabore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip\nex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat\nnulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui of')
但我希望它輸出這樣的:
(13, '[email protected]', 'hello', ' amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut\nlabore et dolore magna aliqua. Ut')
(12, '[email protected]', 'hello', 'orem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor i')
(11, '[email protected]', 'hello', 'consectetur adipisicing elit, sed do eiusmod tempor incididunt ut\nlabore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip\nex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat\nnulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui of')
什麼是最簡單,最有效的方法呢?
1.您的Python有一個語法錯誤。 2.你沒有真正解釋你如何呈現HTML。你使用什麼框架/模板語言? – 2013-04-29 08:38:15
這是一個難以回答的問題嗎?而且這個輸出有點傻。那不是*真的*你想要的是什麼? – 2013-04-29 08:51:16
我剛剛意識到,你甚至不顯示完整的代碼。這個問題在當前狀態下並不真正負責,這涉及到太多的猜測。 – 2013-04-29 08:59:10