连接数据库sqlite3
Django将关系型的表(table)转换成为一个类(class)。而每个记录(record)是该类下的一个对象(object)。
在models.py中,创建一个只有一列的表
from django.db import models
# Create your models here.
class Character(models.Model):
name = models.CharField(max_length=200)
def __unicode__(self):
return self.name
++++
在west/views.py中,添加视图
def staff(request):
staff_list = Character.objects.all()
staff_str = map(str, staff_list)
return HttpResponse(“<p>” + ‘ ‘.join(staff_str) + “</p>”)
在west/urls.py增加url导航
url(r’^staff/’,views.staff),
在浏览器中输入URL:
127.0.0.1:8000/west/staff
OK~~~~~~~~~~~~~~~