Skip to content

Commit

Permalink
views.pyの修正
Browse files Browse the repository at this point in the history
  • Loading branch information
KobashiYu committed Jun 27, 2024
1 parent e213253 commit 4fc64af
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions accounts/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf import settings
from django.contrib.auth import authenticate, login
from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import render
from django.shortcuts import get_object_or_404
from django.urls import reverse_lazy
from django.views.generic import CreateView, TemplateView

Expand All @@ -28,11 +28,9 @@ def form_valid(self, form):
class UserProfileView(LoginRequiredMixin, TemplateView):
template_name = "accounts/profile.html"

def get(self, request, username):
user = User.objects.get(username=username)
tweets = Tweet.objects.filter(user=user).order_by("-created_at")
return render(
request,
self.template_name,
{"user": user, "tweets": tweets},
)
def get_context_data(self, username):
context = super().get_context_data()
user = get_object_or_404(User, username)
context["user"] = username
context["tweets"] = Tweet.objects.select_related("user").filter(user=user).order_by("-created_at")
return context

0 comments on commit 4fc64af

Please sign in to comment.