title: Delete data form after sending post request
body: <p>I'm coding user management page. In page, I have form to add new user with post request and delete button with comfirmation form. I add new user successfully, page is reloaded, then I delete any account, but data in form I sent request to create new user is sent again with new user ID. How to fix?</p>
  
  <h1>user_management.html</h1>
  
  <pre><code>{% extends 'pages/base.html' %}
  {% block title %} Quản lý người dùng{% endblock %}
  {% block active %}
  {% endblock %}
  {% block link %}
      &lt;!-- Latest compiled and minified CSS --&gt;
      &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
            integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"&gt;
  
      &lt;!-- Optional theme --&gt;
      &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
            integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"&gt;
  
      &lt;!-- Latest compiled and minified JavaScript --&gt;
      &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
              integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
              crossorigin="anonymous"&gt;&lt;/script&gt;
  {% endblock %}
  {% load static %}
  {% block css %}
      &lt;link rel="stylesheet" type="text/css" href="{% static 'css/user_management.css' %}"&gt;
      &lt;style&gt;
          #messages {
              width: 200px;
              height: 50px;
              text-align: center;
          }
      &lt;/style&gt;
  {% endblock %}
  {% block content %}
      &lt;div class="container"&gt;
          &lt;div class="table-wrapper"&gt;
              &lt;div class="table-title"&gt;
                  &lt;div class="row"&gt;
                      &lt;div class="col-sm-5"&gt;
                          &lt;h2&gt;Quản lý người dùng&lt;/h2&gt;
                      &lt;/div&gt;
                      &lt;div class="col-sm-7"&gt;
                          &lt;button type="button" class="btn btn-primary" data-toggle="modal"
                                  data-target="#modalRegisterForm"&gt;
                              &lt;i class="material-icons"&gt;&amp;#xE147;&lt;/i&gt;
                              &lt;span&gt;Thêm mới&lt;/span&gt;&lt;/button&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              {% ifequal msg null %}
              {% else %}
                  &lt;div id="messages" class="alert alert-success" role="alert"&gt;
                      &lt;span class=""&gt;{{ msg }}&lt;/span&gt;
                  &lt;/div&gt;
              {% endifequal %}
              &lt;p id="delete-notifa"&gt;&lt;/p&gt;
              &lt;table class="table table-striped table-hover"&gt;
                  &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th&gt;User ID&lt;/th&gt;
                      &lt;th&gt;Name&lt;/th&gt;
                      &lt;th&gt;Date Created&lt;/th&gt;
                      &lt;th&gt;Action&lt;/th&gt;
                  &lt;/tr&gt;
                  &lt;/thead&gt;
                  &lt;tbody&gt;
  
                  {% for user in users %}
                      &lt;tr&gt;
                          &lt;td&gt;{{ user.id }}&lt;/td&gt;
                          &lt;td&gt; {{ user.first_name }} {{ user.last_name }}&lt;/td&gt;
                          &lt;td&gt;{{ user.date_joined }}&lt;/td&gt;
                          &lt;td&gt;
                              &lt;a href="{% url 'profile' user.id %}" class="edit" title="Edit" data-toggle="tooltip"&gt;&lt;i
                                      class="material-icons"&gt;&amp;#xE8B8;&lt;/i&gt;&lt;/a&gt;
                              &lt;a href="#comfirmationForm" class="delete" title="Delete" data-toggle="modal"
                                 data-id="{{ user.id }}"&gt;&lt;i
                                      class="material-icons"&gt;&amp;#xE5C9;&lt;/i&gt;&lt;/a&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  {% endfor %}
                  &lt;/tbody&gt;
              &lt;/table&gt;
              &lt;div class="clearfix"&gt;
                  &lt;div class="hint-text"&gt;Showing &lt;b&gt;5&lt;/b&gt; out of &lt;b&gt;25&lt;/b&gt; entries&lt;/div&gt;
                  &lt;ul class="pagination"&gt;
                      &lt;li class="page-item disabled"&gt;&lt;a href="#"&gt;Previous&lt;/a&gt;&lt;/li&gt;
                      &lt;li class="page-item"&gt;&lt;a href="#" class="page-link"&gt;1&lt;/a&gt;&lt;/li&gt;
                      &lt;li class="page-item"&gt;&lt;a href="#" class="page-link"&gt;2&lt;/a&gt;&lt;/li&gt;
                      &lt;li class="page-item active"&gt;&lt;a href="#" class="page-link"&gt;3&lt;/a&gt;&lt;/li&gt;
                      &lt;li class="page-item"&gt;&lt;a href="#" class="page-link"&gt;4&lt;/a&gt;&lt;/li&gt;
                      &lt;li class="page-item"&gt;&lt;a href="#" class="page-link"&gt;5&lt;/a&gt;&lt;/li&gt;
                      &lt;li class="page-item"&gt;&lt;a href="#" class="page-link"&gt;Next&lt;/a&gt;&lt;/li&gt;
                  &lt;/ul&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="modal fade mt-5" id="modalRegisterForm" tabindex="-1" role="dialog"
           aria-labelledby="myModalLabel" aria-hidden="true"&gt;
          &lt;div class="modal-dialog modal-dialog-centered" role="document"&gt;
              &lt;div class="modal-content"&gt;
                  &lt;div class="modal-header text-xs-center"&gt;
                      &lt;h5 class="modal-title font-weight-bold" id="myModalLabel"&gt;Thêm người dùng&lt;/h5&gt;
                      &lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&gt;
                          &lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;
                      &lt;/button&gt;
                  &lt;/div&gt;
                  &lt;div class="modal-body mx-3"&gt;
                      &lt;form action="{% url 'user_management' %}" method="post" id="addNewUser"&gt;
                          {% csrf_token %}
                          &lt;div class="form-group"&gt;
                              &lt;div class="row"&gt;
                                  &lt;div class="col-xs-6"&gt;
                                      &lt;input type="text" class="form-control" name="first_name" id="first_name"
                                             placeholder="First Name"&gt;
                                  &lt;/div&gt;
                                  &lt;div class="col-xs-6"&gt;
                                      &lt;input type="text" class="form-control" name="last_name" id="last_name"
                                             placeholder="Last Name"&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;input type="email" class="form-control" name="email" placeholder="Email" id="email"
                                     required="required"&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;input type="password" class="form-control" name="password" placeholder="Password"
                                     id="id_password"
                                     required="required"&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;input type="password" class="form-control" name="confirm_password" id="id_comfirm_pass"
                                     placeholder="Confirm Password" required="required"
                                     onkeyup="matchingPassword('id_password', 'id_comfirm_pass', 'msg');"&gt;
                          &lt;/div&gt;
                          &lt;p id="msg"&gt;&lt;/p&gt;
                          &lt;div class="form-group"&gt;
                              &lt;button type="submit" class="btn btn-success btn-lg btn-block" name="add"&gt;Thêm&lt;/button&gt;
                          &lt;/div&gt;
                      &lt;/form&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div id="comfirmationForm" class="modal fade"&gt;
          &lt;div class="modal-dialog modal-confirm"&gt;
              &lt;div class="modal-content"&gt;
                  &lt;div class="modal-header"&gt;
                      &lt;div class="icon-box"&gt;
                          &lt;i class="material-icons"&gt;&amp;#xE5CD;&lt;/i&gt;
                      &lt;/div&gt;
                      &lt;h4 class="modal-title"&gt;Xác nhận&lt;/h4&gt;
                      &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
                  &lt;/div&gt;
                  &lt;div class="modal-body"&gt;
                      &lt;p&gt;Do you really want to delete this user?&lt;/p&gt;
                  &lt;/div&gt;
                  &lt;div class="modal-footer"&gt;
                      &lt;button type="submit" class="btn btn-danger" id="btn_button"&gt;Delete&lt;/button&gt;
                      &lt;button type="button" class="btn btn-info" data-dismiss="modal"&gt;Cancel&lt;/button&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  {% endblock %}
  {% block script %}
      &lt;script&gt;
          function matchingPassword(id_pass, id_comfirm_pass, id_msg) {
              var pass = document.getElementById(id_pass).value;
              var comfirm_pass = document.getElementById(id_comfirm_pass).value;
  
              if (pass != comfirm_pass) {
                  document.getElementById(id_msg).style.color = 'red';
                  document.getElementById(id_msg).innerHTML = "Mật khẩu không trùng nhau";
              } else {
                  document.getElementById(id_msg).innerHTML = "";
              }
          }
      &lt;/script&gt;
      &lt;script&gt;
          var tmp;
          $('.delete').click(function () {
              tmp = $(this).attr('data-id');
          });
          $('#btn_button').click(function () {
              $.ajax({
                  url: '/delete_user',
                  type: 'get',
                  dataType: 'json',
                  data: {
                      user_id: tmp,
                  },
                  success: function (data) {
                      if (data.is_error) {
                          alert("Xóa không thành công");
                          window.location.reload();
                      } else {
                          alert("Xóa thành công");
                          location.reload();
                      }
                  }
              })
          })
          setTimeout(function () {
              $('#messages').hide()
          }, 1000);
  
          setTimeout(function () {
              $('#delete-notifa').hide()
          }, 1000);
      &lt;/script&gt;
  {% endblock %}
  </code></pre>
  
  <h1>views.py</h1>
  
  <pre><code>def user_management(request):
      if request.method == "POST":
          if 'add' in request.POST:
              first_name = request.POST.get('first_name')
              last_name = request.POST.get('last_name')
              username = request.POST.get('email')
              password = request.POST.get('password')
  
              user = User.objects.create_user(username=username, email=username, password=password, first_name=first_name,
                                              last_name=last_name)
              user.save()
              user_info = UserInfor(user=user)
              user_info.save()
  
              user_list = User.objects.all()
              msg = "Thêm thành công"
              return render(request, 'pages/user_management.html', {'users': user_list, 'msg': msg})
          else:
              user_list = User.objects.all()
              msg = "Thất bại"
              return render(request, 'pages/user_management.html', {'users': user_list, 'msg': msg})
      else:
          user_list = User.objects.all()
          return render(request, 'pages/user_management.html', {'users': user_list})
  
  
  def delete_user(request):
      data = {}
      user_id = request.GET.get('user_id')
      user = User.objects.get(id=user_id)
      user_info = UserInfor.objects.get(user_id=user.id)
      user.delete()
      user_info.delete()
      data['is_error'] = User.objects.filter(id=user_id).exists()
      return JsonResponse(data)
  </code></pre>