项目为test01 应用为blog
blog下models views tempaltes目录
models是数据的操作
views是前台展示用的
tempaltes目录是放html页面的
1.vim models.py
from django.db import models
sex_choices=(
('f','famale'),
('m','male'),
)
class Test01(models.Model):
name = models.CharField(max_length=20)
sex = models.CharField(max_length=20,choices=sex_choices)
def __unicode__(self):
return self.name
2.vim views.py
from django.shortcuts import render_to_response
from models import Test01
def index(req):
a = Test01.objects.all()
return render_to_response('index.html',{'sql':a})
3.vim tempaltes/index.html
<html>
<head>
</head>
<body>
`sql`
</body>
</html>
如果想对blog_test01添加数据
交互模式
from models import Test01
a = Test01.objects.create(name='yanchao06',sex='f')
转载于:https://blog.51cto.com/4249964/1600350