Django模型表单能够保存到数据库,但无法显示在模板中

我正在尝试从模型表单中保存输入,并且仅将输入保存到db,直到我转到db并单击“保存”按钮,才将其显示在模板上。我的表单和显示提交的输入的位置在同一HTML页面上。为什么会这样?我似乎找不到原因。由于我是Django新手,请多多包涵。提前致谢。

views.py:

def detail(request, pk):
    prof = get_object_or_404(Prof, pk=pk)
    ratings = Rating.objects.filter(slug=pk)

    paginator = Paginator(ratings, 10)
    page_number = request.GET.get('page')
    page_obj = paginator.get_page(page_number)

    new_rating = None

    # rating posted
    if request.method == 'POST':
        rating_form = RatingForm(data=request.POST)
        if rating_form.is_valid():
            # Create Rating object but don't save to database yet
            new_rating = rating_form.save(commit=False)
            # Assign the current prof to the rating
            new_rating.name = prof
            # Save the rating to the database
            new_rating.save()

    else:
        rating_form = RatingForm()

    return render(request, 'rating/detail.html', {'prof': prof, 'ratings': ratings, 'new_rating': new_rating, 'rating_form': rating_form, 'page_obj': page_obj})

模板:

...

<p class="centerize mt-4">{{ ratings.count }} {% if ratings.count > 1 or ratings.count == 0 %} ratings {% else %} rating {% endif %}</p>
{% for rating in page_obj %}
    <div class="rating-container-detail">
        <div class="card border-secondary">
            <div class="card-header">{{ rating.subject }} - {{ rating.year }} <span class="float-right"> {{ rating.created_on|date:'F j, Y' }} </span></div>
            <div class="card-body">
                <p class="card-title">Helpfulness: <span class="badge badge-primary badge-pill"> {{ rating.helpfulness }}</span> &nbsp; &nbsp;
                                    Pedagogy: <span class="badge badge-primary badge-pill"> {{ rating.pedagogy }} </span> &nbsp; &nbsp;
                                    Easiness: <span class="badge badge-primary badge-pill"> {{ rating.easiness }} </span>
                </p>
                <p class="card-text">{{ rating.comment | linebreaks }}</p>
            </div>
        </div>
    </div>
{% empty %}

    <p class="centerize">No ratings were found for this professor. <br> You may create one if you like: <a class="nav-link" data-toggle="tab" href="#create"> create a review</a></p>
{% endfor %}


...

<div class="ml-auto mr-auto mt-4" style="width: 40%;">
    {% if new_rating %}
        <div class="alert alert-success" role="alert">
            Successfully created rating 
        </div>
    {% else %}
        <form method="post" action="{% url 'rating-detail' prof.pk %}">
            {{ rating_form | crispy }}
            {% csrf_token %}
            <button type="submit" class="btn btn-primary">Submit</button>
        </form>
    {% endif %}
</div>

...

models.py:

class Rating(models.Model):
    helpfulness_choices = (
        (1, 'Very Unhelpful'),
        (2, 'Unhelpful'),
        (3, 'Moderate'),
        (4, 'Helpful'),
        (5, 'Very Helpful'),
    )

    pedagogy_choices = (
        (1, 'Very Low Pedagogy'),
        (2, 'Low Pedagogy'),
        (3, 'Moderate'),
        (4, 'High Pedagogy'),
        (5, 'Very High Pedagogy'),
    )

    easiness_choices = {
        (1, 'Very Difficult'),
        (2, 'Difficult'),
        (3, 'Moderate'),
        (4, 'Easy'),
        (5, 'Very Easy'),
    }

    name = models.ForeignKey(Prof, on_delete=models.CASCADE, related_name="ratings")
    slug = models.SlugField(max_length=110)
    subject = models.CharField(max_length=10)
    year = models.IntegerField(default=0)
    helpfulness = models.IntegerField(choices=helpfulness_choices)
    pedagogy = models.IntegerField(choices=pedagogy_choices)
    easiness = models.IntegerField(choices=easiness_choices)
    comment = models.TextField()
    created_on = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ['created_on']

    def __str__(self):
        return str(self.name)