
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from posts.models import Post, Tag

@login_required
def index(request):
    context = {'posts': Post.objects.all()}
    return render(request, 'dashboard/index.html', context)

@login_required
def tagged_posts(request, tag_name=""):
    context = {'posts': Post.objects.filter(tags__name=tag_name)}
    return render(request, 'dashboard/search_result.html', context)


from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from posts.models import Post, Tag

@login_required
def index(request):
    context = {'posts': Post.objects.all()}
    return render(request, 'dashboard/index.html', context)

@login_required
def tagged_posts(request, tag_name=""):
    context = {
        'tag': tag_name,
        'posts': Post.objects.filter(tags__name=tag_name)
    }
    return render(request, 'dashboard/search_result.html', context)

Modify return tag search data with tag_name
Modify return tag search data with tag_name

  
  from django.shortcuts import render
  from django.contrib.auth.decorators import login_required
  from posts.models import Post, Tag
  
  @login_required
  def index(request):
      context = {'posts': Post.objects.all()}
      return render(request, 'dashboard/index.html', context)
  
  @login_required
  def tagged_posts(request, tag_name=""):
+     context = {
+         'tag': tag_name,
-     context = {'posts': Post.objects.filter(tags__name=tag_name)}
+         'posts': Post.objects.filter(tags__name=tag_name)
+     }
      return render(request, 'dashboard/search_result.html', context)
  
Modify return tag search data with tag_name
## Code Before:

from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from posts.models import Post, Tag

@login_required
def index(request):
    context = {'posts': Post.objects.all()}
    return render(request, 'dashboard/index.html', context)

@login_required
def tagged_posts(request, tag_name=""):
    context = {'posts': Post.objects.filter(tags__name=tag_name)}
    return render(request, 'dashboard/search_result.html', context)

## Instruction:
Modify return tag search data with tag_name
## Code After:

from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from posts.models import Post, Tag

@login_required
def index(request):
    context = {'posts': Post.objects.all()}
    return render(request, 'dashboard/index.html', context)

@login_required
def tagged_posts(request, tag_name=""):
    context = {
        'tag': tag_name,
        'posts': Post.objects.filter(tags__name=tag_name)
    }
    return render(request, 'dashboard/search_result.html', context)
