1.创建应用
python manage.py startapp myblog
2.应用结构
3.创建模型(models.py)
from django.db import models# Create your models here.class BlogPost(models.Model): ''' 博文 ''' title = models.CharField(max_length=150) body = models.TextField() timestamp = models.DateField()
4.配置settings.py
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'myblog']
5.将模型加入自动后台管理(myblog\admin.py)
from django.contrib import admin'''需要在自动后台管理中显示和编辑的应用,在此编写'''# Register your models here.from django.contrib import adminfrom myblog import modelsadmin.site.register(models.BlogPost)
6.测试
a.启动开发服务器
b.访问admin