增加查看所有标签的功能(在articles的app中)
增加url,查看所有标签(articles/urls.py)
# 查看所有的标签
path('column', views.column, name='column'),
在view.py中写这个路由的方法:
def column(request):
# 获得所有的标签内容
columns = Column.objects.all()
# print(columns)
return render(request, 'articles/column.html', locals())
写展示所有标签的html文件:column.html
{% extends 'base.html' %}
{% block title %}标签{% endblock title %}
{% block content %}
<div class="container">
<h4 style="margin-top: 50px">文章标签:</h4>
<hr>
{% for column in columns %}
<h4>
<b>
<a href="{% url 'articles:label' column.id %}" style="color: #383d41; margin-left: 80px; size: A4" title="点击查看使用了该标签的文章">{{ column.title }}</a>
</b>
</h4>
{% endfor %}
</div>
{% endblock content %}
增加了通过某一个标签查看所有使用了该标签的文章的功能