css - html能否替換字符串?
問題描述
網(wǎng)站框架:flask后臺從數(shù)據(jù)庫提取數(shù)據(jù)并向前端傳遞一個參數(shù)[172.16.101.31,172.16.101.32,172.16.101.33]前端獲取參數(shù)后顯示:
但是我需要以列的方式展現(xiàn),目前的修改方式是,數(shù)據(jù)存入數(shù)據(jù)庫的時候把’,’替換’’,這樣傳遞到前端后
目前是以這種方式實現(xiàn)的,但是在數(shù)據(jù)庫里面保存著[172.16.101.31<br/>172.16.101.32<br/>172.16.101.33]這樣的數(shù)據(jù)有點太難看,通過修改html能實現(xiàn)這個需求嗎?
問題解答
回答1:還是以 , 分隔吧, 模版里
<td valign='middle'> {% for ip in mod[2].split(’,’) %} <p>{{ ip }}</p> {% endfor %}</td>
測試代碼
>>> from jinja2 import Template>>> tmpl = '''{% for ip in ips.split(’,’) %} <p>{{ ip }}</p> {% endfor %}'''>>> t = Template(tmpl)>>> print t.render({'ips': '127.0.0.1,192.168.1.1'})
相關(guān)文章:
1. mysql - 新浪微博中的關(guān)注功能是如何設計表結(jié)構(gòu)的?2. MySQL數(shù)據(jù)庫中文亂碼的原因3. angular.js使用$resource服務把數(shù)據(jù)存入mongodb的問題。4. dockerfile - [docker build image失敗- npm install]5. 如何解決Centos下Docker服務啟動無響應,且輸入docker命令無響應?6. angular.js - 關(guān)于$apply()7. nignx - docker內(nèi)nginx 80端口被占用8. 我在centos容器里安裝docker,也就是在容器里安裝容器,報錯了?9. android-studio - Android Studio 運行項目的時候一堆警告,跑步起來?。?/a>10. angular.js - Ionic 集成crosswalk后生成的apk在android4.4.2上安裝失?????
