Python Django ModelView';s";“字段”;属性不工作?
我正在练习Django基于类的观点。Python Django ModelView';s";“字段”;属性不工作?,python,django,django-class-based-views,Python,Django,Django Class Based Views,我正在练习Django基于类的观点。 在使用通用CreateView进行练习时,我很难理解为什么我的“字段”属性不起作用。。。我正试图使用CreateView构建一个帖子创建页面,我只想在帖子页面上显示“帖子标题”和“帖子内容”字段(换句话说,我不想忽略表单上的“用户”和“帖子日期”字段)。我很确定“fields”属性是定义它的正确位置,但是出于某种原因,所有4个字段都出现在Post表单上 这是我的密码: 型号.py class Post(models.Model): user = mo
在使用通用CreateView进行练习时,我很难理解为什么我的“字段”属性不起作用。。。我正试图使用CreateView构建一个帖子创建页面,
我只想在帖子页面上显示“帖子标题”和“帖子内容”字段(换句话说,
我不想忽略表单上的“用户”和“帖子日期”字段)。我很确定“fields”属性是定义它的正确位置,但是出于某种原因,所有4个字段都出现在Post表单上 这是我的密码: 型号.py
class Post(models.Model):
user = models.ForeignKey(User)
post_title = models.CharField(max_length=200)
post_content = models.CharField(max_length=500)
post_date = models.DateTimeField('date posted')
class PostCreate(CreateView):
template_name = 'app_blog/post_save_form.html'
model = Post
fields = ['post_title', 'post_content']
视图.py
class Post(models.Model):
user = models.ForeignKey(User)
post_title = models.CharField(max_length=200)
post_content = models.CharField(max_length=500)
post_date = models.DateTimeField('date posted')
class PostCreate(CreateView):
template_name = 'app_blog/post_save_form.html'
model = Post
fields = ['post_title', 'post_content']
知道为什么这4个字段都出现了吗。。?谢谢:)您必须这样做:
class PostForm(ModelForm):
class Meta:
model = Post
fields = ['post_title', 'post_content']
class PostCreate(CreateView):
template_name = 'app_blog/post_save_form.html'
model = Post
form_class = PostForm
你必须这样做:
class PostForm(ModelForm):
class Meta:
model = Post
fields = ['post_title', 'post_content']
class PostCreate(CreateView):
template_name = 'app_blog/post_save_form.html'
model = Post
form_class = PostForm
CreateView没有属性字段。CreateView没有属性字段。