0

I wrote a simple function that passes some info inside base.html like bellow:

def payment_check(request):
    if request.user.is_authenticated:
        context = {
            'paymentCheck':PaymentInfo.objects.filter(user=request.user)
        }
        return context

but gives me 'NoneType' object is not iterable error.

Sam
  • 379
  • 2
  • 10
  • 2
    **Hint**: What are you returning in case `request.user.is_authenticated` is false? And what is a context processor supposed to return? – Abdul Aziz Barkat Dec 07 '21 at 17:13
  • Does this answer your question? ['NoneType' object is not iterable in Django project](https://stackoverflow.com/questions/59075266/nonetype-object-is-not-iterable-in-django-project) – Abdul Aziz Barkat Dec 07 '21 at 17:14
  • well, a context processor returns a dictionary. I first added @login_required above the function but it gave me this 'dictionary update sequence element #0 has length 0; 2 is required' – Sam Dec 07 '21 at 17:22
  • 1
    Your context processor is not returning a dict if the user is not authenticated. Add else: context={} and move the return statement outside the if else condition. – yagus Dec 07 '21 at 17:35
  • yeah lol I figured it out before you comment! thanks alot for the hint! – Sam Dec 07 '21 at 17:48

0 Answers0