|
本帖最后由 tianzheyiran 于 2018-4-20 23:28 编辑
如下代码,通过 entries 通过 后台views 渲染到web的queryset的对象data_added 和 text 取值正常
通过变量标签{{ entry.id}}获取的id值正常,但是通过 {% url "edit_entry" entry.id %} 获取的 entry.id值不正常,而且刚好是通过变量获取的id值的10倍
哪位大神能指点下吗?
views代码- def topic_view(request,topic_id):
- topic = Topic.objects.get(id = topic_id)
- entries = topic.entry_set.order_by("data_added")
- return render(request,"topic.html",{"topic":topic,"entries":entries})
复制代码
web页面代码
- {% for entry in entries %}
- <li>
- <p>{{ entry.data_added | date }}</p>
- <p>{{ entry.text | linebreaks }}</p>
- <p><a href="/edit_entry/{{ entry.id }}/">编辑</a></p>
- <p><a href="{% url "edit_entry" entry.id %}">编辑</a></p>
- </li>
- {% empty %}
- <li>目前还没有条目</li>
- {% endfor %}
复制代码
|
|