这里实现一个比较简单的评论功能,通过form表单来完成。
实现步骤:
1)创建项目Pro_3:django-admin startproject Pro_3;
创建app:cd Pro_3;python manage.py startapp blog。
2)设计模型(M)
这里包括了两个类:一个是form表单类,一个是评论类,具体形式如下:
#coding=utf-8
from __future__ import unicode_literals
from django.db import models
from django import forms
# Create your models here.
TOPIC_CHOICES=(
('level1','Bad'),
('level2','Soso'),
('level3','Good'),
)
class RemarkForm(forms.Form):
subject=forms.CharField(max_length=100,label='Mark Board')
mail=forms.EmailField(label='email')
topic=forms.ChoiceField(choices=TOPIC_CHOICES,label='choose one topic')
message=forms.CharField(label='content for mark',widget=forms.Textarea)
cc_myself=forms.BooleanField(required=False,label='watch this tie')
class Remark(models.Model):
subject = models.CharField(max_length=100)
mail = models.EmailField()
topic = models.CharField(max_length=100)
message = models.CharField(max_length=