【发布时间】:2019-12-07 05:36:24
【问题描述】:
我在下面的模板中收到此错误
{% for post in post_queryset %}
<div class="card-body">
<div class="date">{{ post.created_date }}</div>
<div class="title">
{{ post.text }}
{{ post.slug }}
<a href="{% url 'editPost' post.slug %}" ><i class="fa fa-edit"></i></a>
<a onClick="delete_post('{{post.slug}}','{{post_id}}')"><i class="fa fa-trash-o"></i></a>
</div>
</div>
{% endfor %}
我在这一行得到错误
<a href="{% url 'editPost' post.slug %}" ><i class="fa fa-edit"></i></a>
我在此行之前显示 {{post.slug}} 并评论链接行只是为了确保 post.slug 有一些内容。看起来 post.slug 有有效的 slug 信息。
我也尝试只传递一些字符串而不是像下面那样的 post.slug 然后它正在工作
<a href="{% url 'editPost' 'some_string' %}" ><i class="fa fa-edit"></i></a>
我的 urls.py 如下所示
path('editPost/<postslug>/',views.editPost, name='editPost')
谁能帮我找出错误?
【问题讨论】:
标签: django django-templates django-urls