admin管理员组

文章数量:1397219

This is my model.py file code:

class Review(models.Model):
    VOTE_TYPE = (
        ('up','Up Vote'),
        ('down','Down Vote'),
    )
    owner = models.ForeignKey(Profile, on_delete=models.CASCADE, null = True)
    project = models.ForeignKey(Project, on_delete=models.CASCADE) # when the model is deleted, all the reviews should also be deleted.
    body = models.TextField(null = True, blank=True)
    value = models.CharField(max_length=200, choices = VOTE_TYPE)
    created = models.DateTimeField(auto_now_add=True)
    id = models.UUIDField(default=uuid.uuid4, unique=True,
                           primary_key=True, editable=False)

This is my forms.py code:

class ReviewForm(ModelForm):
    class Meta:
        model = Review
        fields = ['value', 'body']

        labels = {
            'value': 'Place your vote',
            'body': 'Add a comment with your code'
        }

    def __init__(self,*args,**kwargs):
        super(ReviewForm, self).__init__(*args, **kwargs)

        for name,field in self.fields.items():
            field.widget.attrs.update({'class':'input'})

This my html file code

<form class="form" action="{% url 'project' project.id %}" method="POST">
               {% for field in form %} 
               <!-- 'form' IS THE WORLD WE PUT IN CONTEXT DICT IN PROJECTS VIEW. -->
              <div class="form__field">
                <label for="formInput#textarea">{{ field.label }}</label> 
                {{ field }}
              </div>
              {% endfor %}
              <input class="btn btn--sub btn--lg" type="submit" value="Add Review" />
            </form>

The label's CSS is here:

 ments {
  margin-top: 4rem;
  padding-top: 3rem;
  border-top: 2px solid var(--color-light);
}

ments .form label { 
  position: absolute;
  margin: -9999px; 
}

mentList {
  margin: 3rem 0;
}

ment {
  display: flex;
  gap: 2rem;
}

the problem is that Labels are not showing.Can anybody help me how to fix this issue? The picture's inspect will might help.

The image attached to this question will be very helpful.

本文标签: cssLabels in the form is not showingStack Overflow