title: refresh a same page without reloading?
body: <p>I have already asked this question here but none of the answers were working. I have a messaging app in Django where users can send messages each other. I want to refresh the page so that the user can see new messages. But there is one problem if the user is writing a message and I try to reload the page every x-minutes the message that the user was writing will disapear. So how can I avoid this?</p>
  <pre><code>/*This is one of the solutions that I have tried*/
  window.location.reload(true);
  history.go(0);
  window.location.href=window.location.href;
  </code></pre>
  <p>messages.html:</p>
  <pre><code>{% extends 'profile/base.html' %}
  {% load tz %}
  {% block title %}
  Messages
  {% endblock %}
  {% block head %}
    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css&quot;&gt;
    &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js&quot;&gt;&lt;/script&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css&quot;&gt;
    &lt;style&gt;
            #form {
              position: fixed;
              bottom: 0;
              background-color:#f1f1f1;
            }
  .container {
    border: 1px solid #dedede;
    background-color: #f1f1f1;
    border-radius: 5px;
    padding: 1px;
    margin: 1px 0;
  }
  
  
  .container::after {
    content: &quot;&quot;;
    clear: both;
    display: table;
  }
  
  .darker {
    border-color: #ccc;
    background-color:#ddd;
  }
  
  .container img {
    float: left;
    max-width: 40px;
    height:40px;
    width: 100%;
    margin-right: 20px;
    border-radius: 50%;
  }
  
  .time-left {
    margin-left:61px;
    color: #999;
  }
  
  h4 {
      display:inline;
  }
      &lt;/style&gt;
  {% endblock %}
  {% block content %}
  {% if not chat %}
      &lt;div class=&quot;container&quot;&gt;
           Impossible de commencer un chat avec cet utilisateur ou bien vous n'avez pas acces a ce chat.
      &lt;/div&gt;
  {% else %}
      {% if chat %}
          &lt;div id ='bottom' class=&quot;panel&quot;&gt;
                  {% for message_item in chat.message_set.all %}
                  {% url 'profile' message_item.author.pk as the_user_url%}
      {% if message_item.is_readed %}
      &lt;div class=&quot;container&quot;&gt;
      {% else %}
      &lt;div class=&quot;container darker&quot;&gt;
      {% endif %}
      &lt;a href=&quot;{{ the_user_url }}&quot;&gt;
  
    &lt;img src=&quot;{{ message_item.author.profile.avatar.url }}&quot; alt=&quot;Avatar&quot; style=&quot;width:100%;&quot;&gt;
    &lt;h4&gt;&lt;a href=&quot;{{ the_user_url }}&quot;&gt;{{ message_item.author.profile.prenom|title }}&lt;/a&gt;&lt;/h4&gt;
    &lt;p&gt;{{ message_item.message }}&lt;/p&gt;
    &lt;span class=&quot;time-left&quot;&gt;{{ message_item.pub_date|utc }}&lt;/span&gt;
    &lt;/a&gt;
  &lt;/div&gt;
  
                  {% endfor %}
                  &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      {% endif %}
  
      &lt;div class='w3-container'&gt;
      &lt;div id='form'&gt;
          &lt;form method=&quot;post&quot; action='{% url 'messages' chat.id %}'&gt;
              {% csrf_token %}
              {{ form.as_p }}
  
              &lt;input type=&quot;submit&quot; value='envoyez' /&gt;
              &lt;/form&gt;
          &lt;/div&gt;
          &lt;/div&gt;
          &lt;script src=&quot;http://code.jquery.com/jquery-1.8.1.min.js&quot;&gt;&lt;/script&gt;
          &lt;script&gt;
          $('document').ready(function() {
             $('html').animate({scrollTop: document.body.scrollHeight},1);
          });
          &lt;/script&gt;
  {% endif %}
  {% endblock %}
  </code></pre>
  <p>urls.py:</p>
  <pre><code>from django.urls import path
  from . import views
  
  urlpatterns = [
      path('dialogs/&lt;int:chat_id&gt;/',views.MessagesView.as_view(), name='messages'),
      ]
  </code></pre>