django中的模板语言
1.html页面存放templates(模板)之中
html中使用模板语言加入从数据库中取出的数据
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>my</title>
</head>
<body>
<h1>{{ user }}</h1>
<table border="1">
{% for item in data %}
<tr>
<td>{{ item.id }}</td>
<td>{{ item.hostname }}</td>
<td>{{ item.creat_time }}</td>
<td>{{ item.update_time }}</td>
</tr>
{% endfor %}
</table>
</body>
</html>
2.views业务控制中添加如下方法:
from django.shortcuts import render_to_response
def AssetList(request, kwargs):
asset_list = Asset.objects.all()
result = render_to_response('my.html', {'data': asset_list, 'user': 'yh'})
return result
3.在urls中添加映射,然后在浏览器中输入即可显示相应的html
http://127.0.0.1:8000/web/AssetList/