[Fixed]-TypeError at /accounts/tcresults

1πŸ‘

βœ…

The object is not iterable because :

 ImageAndUser.objects.filter(user=request.user).order_by('id').last()

This filter condition returned only last object in the list. One resulting element is not iterable.

I suggest you modify your code and try to print the number of items in the query set.

def tc(request):
    tcresults = ImageAndUser.objects.filter(user=request.user).order_by('id').last()
    print tcresults, ' queryset'
    print len(tcresults), ' length'
    d = {
        'tcresults': tcresults,
    }
    return render(request, 'registration/accounts/tc.html', d)

And update your html code like this :

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>tc</title>
</head>
<body>
    <h2>
    γ€€γ€€γ€€{{ tcresults.tc }}
    </h2>
</body>
</html>

0πŸ‘

Remove the .last() from your query in your code above.

πŸ‘€Udi

Leave a comment