title: how to check whether user is logged in or not
body: <p>I am working on invoice management system in which user can add invoice data and it will save in database and whenever user logged in the data will appear on home page but whenever user logout and try to access home page but it is giving following error.</p>
  
  <pre><code>TypeError at /
  
  'AnonymousUser' object is not iterable
  </code></pre>
  
  <p>i tried <code>AnonymousUser.is_authenticated</code> method but still not working.</p>
  
  <p>i want if user is logged in then <code>home.html</code> should open otherwise <code>intro.html</code></p>
  
  <p>here is my code
  views.py</p>
  
  <pre><code>
  from django.shortcuts import render
  from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
  from django.views.generic import (
      ListView,
      DetailView,
      CreateView,
      UpdateView,
      DeleteView
  )
  from .models import Invoicelist
  
  def home(request):
  
      if request.user.is_authenticated():
          context = {
          'invoices': Invoicelist.objects.all()
          }
          return render(request, 'invoicedata/home.html', context)
  
      else:
          return render(request, 'invoicedata/intro.html', context)
  </code></pre>
  
  <p>home.html</p>
  
  <pre><code>{% extends "invoicedata/base.html" %}
  {% block content %}
        {% for invoice in invoices %}
        &lt;article class="media content-section"&gt;
          &lt;div class="media-body"&gt;
            &lt;div class="article-metadata"&gt;
              &lt;small class="text-muted"&gt;{{ invoice.date_posted|date:"F d, Y" }}&lt;/small&gt;
              &lt;h2&gt;&lt;a class="article-title" href="{% url 'invoice-detail' invoice.id %}"&gt;{{ invoice.issuer }}&lt;/a&gt;&lt;/h2&gt;
            &lt;/div&gt;
  
            &lt;p class="article-content"&gt;{{ invoice.invoice_number }}&lt;/p&gt;
            &lt;p class="article-content"&gt;{{ invoice.date }}&lt;/p&gt;
            &lt;p class="article-content"&gt;{{ invoice.amount }}&lt;/p&gt;
            &lt;p class="article-content"&gt;{{ invoice.currency }}&lt;/p&gt;
            &lt;p class="article-content"&gt;{{ invoice.other }}&lt;/p&gt;
            &lt;div class="article-metadata"&gt;
              &lt;small class="text-muted"&gt;{{ invoice.author }}&lt;/small&gt;
            &lt;/div&gt;
  
          &lt;/div&gt;
        &lt;/article&gt;
        {% endfor %}
  {% endblock content %}
  </code></pre>
  
  <p>intro.html</p>
  
  <pre><code>{% extends "invoicedata/base.html" %}
  {% block content %}
      &lt;h2&gt;login to your portal for great auditing services&lt;/h2&gt;
  {% endblock content %}
  </code></pre>