微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决注释未在我的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”),“

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。