http://127.0.0.1:8000/boards/1/
python manage.py migrate #boards/models.py class Topic(models.Model): views = models.PositiveIntegerField(default=0) # <- here python manage.py makemigrations python manage.py migrate #boards/views.py def topic_posts(request, pk, topic_pk): topic = get_object_or_404(Topic, board__pk=pk, pk=topic_pk) topic.views += 1 topic.save() return render(request, 'topic_posts.html', {'topic': topic}) <!--templates/topics.html--> {% for topic in topics %} <tr> <td><a href="{% url 'topic_posts' board.pk topic.pk %}">{ { topic.subject }}</a></td> <td>{ { topic.starter.username }}</td> <td>{ { topic.replies }}</td> <td>{ { topic.views }}</td> <!-- here --> <td>{ { topic.last_updated }}</td> </tr> {% endfor %}
转载于:https://www.cnblogs.com/larken/p/9565148.html
原文链接:https://blog.csdn.net/weixin_30342827/article/details/96385242
本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。
还没有人抢沙发呢~