Представление account.views.profile не возвращало объект HttpResponse. Вместо этого он вернулся - PullRequest
0 голосов
/ 10 июля 2019

вот мои взгляды.

def profile(request, username):
    if User.objects.filter(username=username).exists():
        u = User.objects.filter(username=username)[0]

        if not Followers.objects.filter(user=username, follower=request.user.username).exists():
            following = "Follow"
            cls = "btn-p"
        else:
            following = "Following"
            cls = "btn-t"

        if u.profilepic == "":
            u.profilepic = "static/assets/img/default.png"

        followers_p = 0
        following_p = 0
        posts = 0

        name = u.name
        bio = u.bio


        posts = Photo.objects.filter(owner=username)
        posts = len(posts)

        followers_p = len(Followers.objects.filter(user=username))
        following_p = len(Followers.objects.filter(follower=username))

        context = {
            'ProfilePic': u.profilepic, "whosprofile": username, "logged_in_as": request.user.username, "following": following, "cls":cls, "posts":posts, "followers_p":followers_p, "following_p": following_p,"name":name, "bio":bio
        }

        if request.user.is_authenticated:
            return render(request, 'logged-in-profile.html', context)
        return render(request, 'profile.html', context)

1 Ответ

1 голос
/ 10 июля 2019

Вы ничего не вернули, если имя пользователя не существует, поэтому оно вернуло None.

 def profile(request, username):
        if User.objects.filter(username=username).exists():
           ......................
        else:
            return HttpResponse('No user found')
             #return 'something'
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...