为了账号安全,请及时绑定邮箱和手机立即绑定

仅显示更新和删除链接以在 Django 中发布作者

仅显示更新和删除链接以在 Django 中发布作者

HUWWW 2023-06-13 11:13:07
我只想显示更新和删除链接到 django 博客中帖子的作者。但是{% if request.user == posts.author %}在模板上抛出错误Could not parse the remainder: '==posts.author' from 'request.user==posts.author'。我该如何解决这个问题?Views.pydef post_detail(request,slug):    posts=Post.objects.get(slug=slug)    posts.seen_by=posts.seen_by+1    posts.save()    context={'posts':posts}    return render(request,'blog/post_detail.html',context)post_detail.html{% extends 'blog/base.html'%}{% block content%}        <a href="{%url 'post-cate' posts.category %}">{{posts.category}}</a>            <p>{{posts.date_posted}}</p>        <h1>{{posts.title}}</h1>        {% if request.user==posts.author %}        <p><a href="{% url 'post-update' posts.slug %}">Update</a> <a href="{% url 'post-delete' posts.slug %}">Delete</a> </p>        {% endif%}            <strong>{{posts.content}}</strong><p>- <a href="{% url 'post-by-user' posts.author %}">{{posts.author}}</a></p>            Seen:{{posts.seen_by}}            <hr>{% endblock content%}
查看完整描述

1 回答

?
慕码人8056858

TA贡献1803条经验 获得超6个赞

你应该在符号周围放置空格==

{% if request.user == posts.author %}
                ^^^^^^^^


查看完整回答
反对 回复 2023-06-13
  • 1 回答
  • 0 关注
  • 90 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信