注释未在我的Django Python网站上打印出来

问题描述

因此,在名为commentQuery的字典中得到了一堆注释对象。但是,这些评论不会在实际的帖子页面上打印出来。

有人知道为什么吗?谢谢! (如您所见,我正在尝试同时使用commentQueries和commentQuery选项-均未显示页面上!)

views.py:

def comment(request):
username = request.POST.get("username")
itemID = request.POST.get("itemID")
comment = request.POST.get("comment")
new = Comment.objects.create(username = username,comment = comment,itemID = itemID)
new.save()
commentQuery = Comment.objects.all()
return render(request,"auctions/post.html",{ "commentQuery": commentQueries})

post.html:

    <form name="comment"
          action="/comment"
          method="post">
        {% csrf_token %}
    <h2>Comments</h2>
    {% if user.is_authenticated %}
    <input autofocus class="form-control" type="text" name="comment" placeholder="Enter Comment">
    <input autofocus class="form-control" type="hidden" name="itemID" value={{p.title}}{{p.price}}>
    <input autofocus class="form-control" type="hidden" name="username" value={{user.username}}>
    <input class="btn btn-primary" type="submit" value="Add Comment">
    {% endif %}
    </form>
{% for commentQuery in commentQueries %}
            <li>{{ commentQuery.comment }} by {{ commentQueries.username }}</li>
{% endfor %} 
        
{% endblock %}

解决方法

我将路径更改为path(“ comment”,views.comment,name =“ comment”),“