title: How to always display model data in Django template after reloading a page?
body: <p>Scenario:</p>
  
  <p>Currently, <strong>my Template has a text which says "Last seen" and a timer that mentions the time generated after clicking a button</strong>. If a new user visits the site, there will be no time displayed. If a user clicks on the button, the time will be generated and created in the model. And every time a user refreshes the page, the old/current time should be displayed near the text. Right now, every time I reload the page, there is no time displayed despite being saved in my model. How can I show the current time in my Template after reloading each time?</p>
  
  <p>This is what I have tried out so far:</p>
  
  <p>models.py:</p>
  
  <pre><code>from django.contrib.auth.models import User
  
  class Path(models.Model):
      user = models.OneToOneField(User, on_delete = models.CASCADE)
      current_time = models.DateTimeField(blank=True, null=True)  #can be Null or blank if users enters the site for the first time.
  </code></pre>
  
  <p>views.py:</p>
  
  <pre><code>from django.utils import timezone 
  import pytz
  from django.http import JsonResponse, HttpResponse
  
  def Func():
      '''
      If the current_time does not exist, then we create it in the Path model.
      #If time already exists, then we grab the id and replace current time with a new one using the update() method. 
      '''
      time = timezone.now()  #Format: 2019-11-16 14:53:35.774824+00:00
      user_id = request.user.id      #User id = 1
      if (Path.objects.filter(current_time = time) in (None, '')): 
          time = Path.objects.create(current_time = time)
      else:
          time = Path.objects.filter(user_id=user_id).update(current_time = time) 
      obj = Path.objects.values_list('current_time', flat=True)
      return HttpResponse(obj)  
  </code></pre>
  
  <p>home.html:</p>
  
  <pre><code>... HTML stuff here
  #If time exists in model, then display it in Template (even after refreshing/reloading)
  {% if obj.current_time %}
      &lt;div class="placeRight"&gt;
          &lt;p&gt; Last indexed:
              &lt;b&gt; {{obj.current_time}}&lt;/b&gt; 
          &lt;/p&gt; 
      &lt;/div&gt;
  #If time doesn't exist, then display None (this will only occur if a user enters the site for the first time). 
  {% else %}
      &lt;div class="placeRight"&gt;
          &lt;p&gt; Last indexed:
              &lt;b&gt; None &lt;/b&gt; 
          &lt;/p&gt; 
      &lt;/div&gt; --&gt;
  {% endif %}
  </code></pre>
  
  <p>As stated, after each page reload, the time is displayed as 'None' and I have to keep clicking the button for the time to show up. Is there a way to view the time (if existing) after each reload?</p>