from django.shortcuts import render, get_object_or_404
from .models import Post
from django.views.generic import ListView
from taggit.models import Tag
def post_list(request, tag_slug=None):
object_list = Post.published.all()
tag = None
if tag_slug:
tag = get_object_or_404(Tag, slug=tag_slug)
object_list = object_list.filter(tags__name__in=[tag]) # filter the all retrive objects depend on tags path('', views.post_list, name='post_list'),
path('tag/<slug:tag_slug>/',views.post_list, name='post_list_by_tag'),