Website framework: flask
The background extracts data from the database and passes a parameter to the front end [172.16.101.31, 172.16.101.32, 172.16.101.33]
After the front end obtains the parameters, it displays:
But I need to display it in columns. The current modification method is to replace ',' with '
' when the data is stored in the database, and pass it to Front end and back
It is currently implemented in this way, but the data stored in the database [172.16.101.31<br/>172.16.101.32<br/>172.16.101.33] is a bit too ugly. By modifying Can html achieve this requirement?
PHP中文网2017-07-05 10:37:15
Let’s separate it with ,
, in the template
<td valign="middle">
{% for ip in mod[2].split(',') %}
<p>{{ ip }}</p>
{% endfor %}
</td>
Test code
>>> 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"})