再次学习Django,实现sql的页面显示及条件查询

view.py
def search_post(request):
global ctx_2
cursor.execute('select * from testdj_test')
#ctx = {}
ctx_2 = dictfetchall(cursor)
return render(request, "post.html", {'results': ctx_2})


html
<table class="table">
{% for item in results %}
<tr>
<td>{{item.name}}</td>
<td>{{item.age}}</td>
<td>{{item.course}}</td>
</tr>
{%endfor%}
</table>


猜你喜欢

转载自www.cnblogs.com/tangbinghaochi/p/10755608.html