Is there a way to remove repeated tags?

The same tags are being repeated and displayed in the dropdown list. It is looping over the tags used in each post but it is not checking if the tags are repated or not. So is there any way that I can avoid this repetition? my dropdown list is as below:

<div class="dropdown">
    <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                Tags
    </button>
        <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                {% for post in posts %}
                    {% for tag in post.tags.all %}
                        <a class="dropdown-item" href="{% url 'post_tag' tag.slug %}">
                            {{ tag.name }}
                        </a>
                    {% endfor %}
                {% endfor %}

        </div>
</div>

views.py

def home(request, tag_slug=None):
  posts = Post.objects.all()
  #tag post
  tag = None
   if tag_slug:
     tag = get_object_or_404(Tag, slug=tag_slug)
     posts = posts.filter(tags__in=[tag])
    
return render(request, 'blog/home.html', {'posts':posts})

models. py

from taggit.managers import TaggableManager
    class Post(models.Model):
    title = models.CharField(max_length=100)
    content = RichTextUploadingField() 
    date_posted = models.DateTimeField(default=timezone.now)
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    image = models.ImageField(default= 'blog_default.jpg', upload_to='blog-pics')
    tags = TaggableManager()
    
    
        def __str__(self):
             return self.title

urls has

path('tag/<slug:tag_slug>/',views.home, name='post_tag'),

I am using Django-taggit. Help this guy out please.

Use distinct() method of QuerySet objects:

{% for tag in post.tags.all.distinct %}
Back to Top