1. 启动wampserver
2. 新建一个名为mysite的项目
django-admin.py startproject mysite
3. 新建一个叫做blog的app
cd mysite
python manage.py startapp blog
4. 修改blog文件夹中的models.py
# coding:utf-8 from __future__ import unicode_literals from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Article(models.Model): title = models.CharField(u'标题', max_length=256) content = models.TextField(u'内容') pub_date = models.DateTimeField(u'发布时间', auto_now_add=True, editable=True) update_time = models.DateTimeField(u'更新时间', auto_now=True, null=True) def __str__(self): return self.title
把blog加入到settings.py中的INSTALLED_APPS
INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'blog', )
同步所有的数据表
python manage.py makemigrations
python manage.py migrate
创建管理员
python manage.py createsuperuser
Username: asina
Email address: 2016968116@qq.com
Password: liuqiuchen123456
修改admin.py
from django.contrib import admin from .models import Article admin.site.register(Article)
// 打开开发服务器
python manage.py runserver
访问http://localhost:8000/admin/ 输入设定的账号和密码
查看github上源码