django 简单显示数据库的内容,django数据库内容,index.html

index.html

<html lang="en">

<head>

<meta charset="UTF-8">

<title>Upload Successfully</title>

</head>

<body>

<p>所在城市</p>

{% for name in names %}

<p>{{name.city}}</p>

<h2>1</h2>

<p>{{name.name}}</p>

<br>

{% endfor %}

</body>

</html>

from django.http import HttpResponseimport os,syssys.path.insert(0,os.path.abspath(os.curdir))import sqlite3import settingsfrom ms.models import Studentfrom django.shortcuts import HttpResponseRedirect,Http404,HttpResponse,render_to_responsedef archive(request):    names = Student.objects.all()    return render_to_response("index.html",locals())#该片段来自于http://byrx.net

评论关闭