[英]Comments aren't printing out on my Django Python site
所以我在一个名为 commentQuery 的字典中得到了一堆评论对象。 但是,评论不会打印在实际的帖子页面上。
有人明白为什么吗? 谢谢! (如您所见,我正在尝试 commentQueries 和 commentQuery 选项 - 两者都没有显示在页面上!)
视图.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})
后.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"),"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.