第 0023 题: 使用 Python 的 Web 框架,做一个 Web 版本 留言簿 应用。
运行服务器:
python manage.py runserver
2.在settings中添加guestbook应用
3先设计models,models.py
from django.db import models# Create your models here. class Comment(models.Model):name = models.CharField("姓名",max_length=16)content = models.TextField("内容")pub = models.DateField("发布时间", auto_now_add=True)class Meta:verbose_name = "留言"verbose_name_plural = verbose_namedef __unicode__(self):return self.namedef __str__(self):return self.content
4.在admin.py中注册Comment
from django.contrib import admin from .models import Comment# Register your models here. class CommentAdmin(admin.ModelAdmin):list_display = ('name','content','pub')admin.site.register(Comment,CommentAdmin)