html文件
## index##
<body>
{% for k,v in user_dict.items %}
<li style="margin: 50px"><a href="/detail?nid={{ k }}">{{ k }}</a></li>
{% endfor %}
</body>
## detail##
<body>
<h1>详细信息</h1>
<h2>姓名:{{ detail_info.name }}</h2>
<h2>年龄:{{ detail_info.age }}</h2>
</body>
view
user_dict = {
'1': {'name': 'jack1', 'age': '12'},
'2': {'name': 'jack2', 'age': '12'},
'3': {'name': 'jack3', 'age': '12'},
'4': {'name': 'jack4', 'age': '12'},
}
def index(request):
return render(request, 'index.html', {'user_dict': user_dict})
def detail(request):
nid = request.GET.get('nid')
detail_info = user_dict[nid]
return render(request,'detail.html',{'detail_info':detail_info})