(一)修改models
from django.db import models
from blog.models import *
from django.contrib import admin
class BlogPost(models.Model):
title=models.CharField(max_length=150)
body=models.TextField()
timestamp=models.DateTimeField()
def __unicode__(self):
return self.title
class BlogPostAdmin(admin.ModelAdmin):
list_display=('title','timestamp')
admin.site.register(BlogPost,BlogPostAdmin)
(二)修改settings.py
找到INSTALLED_APPS,改为
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
'blog',
)
(三)生成blog表
python manage.py syncdb
(四)启动服务器
python manage.py runserver 8001
此处指定端口为8001,因为我电脑中的8000端口已被占用,界面如下: