Answer the question
In order to leave comments, you need to log in
How to fix matching query does not exist?
Exception Value:
UserProfile matching query does not exist.
def PostList(request):
all_posts = Post.objects.order_by('-timestamp').all()
paginator = Paginator(all_posts, 3)
page = request.GET.get('page', 1)
try:
posts = paginator.page(page)
except PageNotAnInteger:
raise Http404
except EmptyPage:
posts = paginator.page(paginator.num_pages)
post_votes = {}
if request.user.is_authenticated:
for post in posts:
try:
vote = Vote.objects.get(vote_object_type=post.get_content_type(), vote_object_id=post.id, user=UserProfile.objects.get(user=request.user))
post_votes[post.id] = vote.value
except Vote.DoesNotExist:
pass
return render(request, 'posts/post_list.html', {'posts': posts, 'post_votes': post_votes})
Answer the question
In order to leave comments, you need to log in
Um what the...
OK.
Pack UserProfile.objects.get(user=request.user)
in a separate try
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question