title: Django : Type error at/ <User: user1> is not JSON serializable
body: <p>I got a type error showing "  is not JSON serializable". 
  After adding session related code this error comes. </p>
  
  <p>views.py </p>
  
  <pre><code>def jlogin(request):
      if request.method == 'POST':
          username = request.POST['uname']
          password = request.POST['pword']
          user = authenticate(username=username, password=password)
          if user is not None:
              login(request,user)
              print(user)
              request.session['user']=user
              return redirect('/feeds/')
          else:
              return render(request,'join/login.html')
      else:
          user = request.session.get('user')
          print(user)
          if user is None:
              return render(request,'join/login.html')
          else:
              return render(request,'feeds/feeds.html')
  </code></pre>
  
  <p>login.html </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Login to dEEPsIGMA&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form action="." method="post" enctype="multipart/form-data"&gt;
      {% csrf_token %}
      Username :
      &lt;input type="text" name="uname"/&gt; &lt;br&gt;
      Password :
      &lt;input type="text" name ="pword"/&gt;
      &lt;input type="submit"&gt;
  
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Traceback:</p>
  
  <pre><code>File "C:\Python27\lib\site-packages\django-1.8-py2.7.egg\django\core\handlers\base.py" in get_response
    207.                 response = middleware_method(request, response)
  File "C:\Python27\lib\site-packages\django-1.8-py2.7.egg\django\contrib\sessions\middleware.py" in process_response
    49.                         request.session.save()
  File "C:\Python27\lib\site-packages\django-1.8-py2.7.egg\django\contrib\sessions\backends\db.py" in save
    58.             session_data=self.encode(self._get_session(no_load=must_create)),
  File "C:\Python27\lib\site-packages\django-1.8-py2.7.egg\django\contrib\sessions\backends\base.py" in encode
    89.         serialized = self.serializer().dumps(session_dict)
  File "C:\Python27\lib\site-packages\django-1.8-py2.7.egg\django\core\signing.py" in dumps
    89.         return json.dumps(obj, separators=(',', ':')).encode('latin-1')
  File "C:\Python27\lib\json\__init__.py" in dumps
    250.         sort_keys=sort_keys, **kw).encode(obj)
  File "C:\Python27\lib\json\encoder.py" in encode
    207.         chunks = self.iterencode(o, _one_shot=True)
  File "C:\Python27\lib\json\encoder.py" in iterencode
    270.         return _iterencode(o, 0)
  File "C:\Python27\lib\json\encoder.py" in default
    184.         raise TypeError(repr(o) + " is not JSON serializable")
  
  Exception Type: TypeError at /
  Exception Value: &lt;User: user1&gt; is not JSON serializable
  </code></pre>
  
  <p>please help to solve this error. Explain why this error is occurred . </p>