首先引用Blog文件
from blog.models import Blog
查询所有的博客
Blog.object.all()
查询博客的数量
Blog.objects.all.count()
定义变量
blog=Blog()
引用博客类型
from blog.models import BlogType
查看所有博客类型
BlogType.objects.all()
显示第一个博客类型,同时赋值给变量
blog_type = BlogType.objects.all()[0]
引用作者模块
from django.contrib.auth.models import User
显示第一个作者并赋值
blog.author = User.objects.all()[0]
保存文章
blog.save()
利用循环创作31篇文章
for i in range (1,31):
...: blog=Blog()
...: blog.title = "for %s"%i
...: blog.content = "xxxxxx:%s"%i
...: blog.blog_type = blog_type
...: blog.author = user
...: blog.save()
总体的模板