因此,在crispy表单文档中(此处链接:https://django-crispy-forms.readthedocs.io/en/latest/crispy_tag_forms.html#change-required-fields),它指出:
星号有一个asteriskField类集。所以你可以使用CSS规则隐藏它。
models.py
class Post(models.Model, HitCountMixin):
title = models.CharField(max_length=100)
content = models.TextField()
date_posted = models.DateField(auto_now_add=True)
image = models.ImageField(default='default_pics/default_post.jpg', upload_to='post_pics')
# a teacher can have many blog posts
author = models.ForeignKey(Teacher, on_delete=models.SET_NULL, null=True)
forms.py
class BlogFrom(forms.ModelForm):
class Meta:
model = Post
fields = ['title', 'content', 'image']
widgets = {
'image': forms.FileInput(attrs={"class":"asteriskField"})
}
help_texts = {
'image': 'If you do not set any image, one will be set automatically for you upon creation.'
}
我不知道该怎么办。请帮帮我!
1条答案
按热度按时间q5iwbnjs1#
如文档中所述,你可以将
.asteriskField {display: none; }
添加到你的css文件中,如果你使用的话。或者你可以将<style> .asteriskField {display: none; } </style>
添加到你的模板的头文件中。