标签:对象 tin model nbsp redirect create 进阶 cut direct
在models.py里面添加
from django.db import models # Create your models here. class UserInfo(models.Model): nid = models.AutoField(primary_key=True) username = models.CharField(max_length=32) pwd = models.CharField(max_length=32) age = models.IntegerField()
在settings.py里的INSTALLED_APPS里加入要建表的app的名称。
在命令行执行:python manage.py makemigrations
python manage.py migrate
注:
类 --> 数据库的表
字段 --> 列
对象 --> 一行数据
从数据库获取数据
from django.shortcuts import render,redirect from app01 import models # Create your views here. def users(request): user_list = models.UserInfo.objects.all() #从数据库获取数据 print(user_list) return render(request,‘servers.html‘,{‘server_list‘:user_list})
标签:对象 tin model nbsp redirect create 进阶 cut direct
原文地址:http://www.cnblogs.com/xone/p/6548623.html