title: How to delete user with confirmation by passing url and username var in django
body: <p>i have html that show the list of user created in this application in table
  here's the html</p>
  
  <pre><code>&lt;div class="row mt"&gt;
            &lt;div class="col-md-12"&gt;
              &lt;div class="content-panel align-content-center"&gt;
                &lt;table class="table table-striped table-advance table-hover"&gt;
                  &lt;thead&gt;
                    &lt;tr&gt;
                      &lt;th&gt;&lt;i class="fa fa-bullhorn"&gt;&lt;/i&gt; User&lt;/th&gt;
                      &lt;th&gt;&lt;i class="fa fa-bookmark"&gt;&lt;/i&gt; Email&lt;/th&gt;
                      &lt;th&gt;&lt;i class="fa fa-bookmark"&gt;&lt;/i&gt; Division&lt;/th&gt;
                      &lt;th&gt;&lt;i class="fa fa-bookmark"&gt;&lt;/i&gt; Role&lt;/th&gt;
                      &lt;!-- &lt;th&gt;&lt;i class=" fa fa-edit"&gt;&lt;/i&gt; Status&lt;/th&gt; --&gt;
                      &lt;th&gt;&lt;/th&gt;
                    &lt;/tr&gt;
                  &lt;/thead&gt;
                  &lt;tbody&gt;  
                    {% for user in users %}
                      &lt;tr&gt;
                        &lt;td class="user_name"&gt;
  
                          {{user.name}}
  
                        &lt;/td&gt;
                        &lt;td&gt;
                          {{user.email}}
                        &lt;/td&gt;
                        &lt;td&gt;
                          {{user.division}}
                        &lt;/td&gt;
                        &lt;td&gt;
                        &lt;select id="userroles" class="roleselect" data-username="{{ user.name }}"&gt;                        
                          &lt;option selected="selected"&gt;
                            {{user.role}}
                          &lt;/option&gt;
                          {% if user.role == "Business Analyst" %}
                             &lt;option&gt;Admin&lt;/option&gt;
                             &lt;option&gt;Manager&lt;/option&gt;
                             &lt;option&gt;Segment Manager&lt;/option&gt;
                          {% elif user.role == "Admin" %}
                             &lt;option&gt;Business Analyst&lt;/option&gt;
                             &lt;option&gt;Manager&lt;/option&gt;
                             &lt;option&gt;Segment Manager&lt;/option&gt;
                          {% elif user.role == "Manager" %}
                             &lt;option&gt;Admin&lt;/option&gt;
                             &lt;option&gt;Business Analyst&lt;/option&gt;
                             &lt;option&gt;Segment Manager&lt;/option&gt;
                          {% else %}
                             &lt;option&gt;Admin&lt;/option&gt;
                             &lt;option&gt;Manager&lt;/option&gt;
                             &lt;option&gt;Business Analyst&lt;/option&gt;                       
                          {% endif %}
                        &lt;/select&gt;
                        &lt;/div&gt;
                        &lt;/td&gt;                    
                      &lt;td&gt;                  
                         &lt;button  class="btn btn-danger btn-xs" onclick="myFunction()"&gt;&lt;i class="fa fa-trash-o "&gt;&lt;/i&gt;&lt;/button&gt;
                      &lt;/td&gt;
                    &lt;/tr&gt;
                    {% endfor %}   
  
                  &lt;/tbody&gt;
                &lt;/table&gt;
              &lt;/div&gt;
              &lt;!-- /content-panel --&gt;
            &lt;/div&gt;
            &lt;!-- /col-md-12 --&gt;
          &lt;/div&gt;
          &lt;!-- /row --&gt;
        &lt;/section&gt;
      &lt;/section&gt;
  </code></pre>
  
  <p>i want to make a delete function that need a confirmation , before that i use the onlick =  "window.location.href ='{% url 'polls:deleteuser' user_name=user.name %}';", and it works but now i want to make a confirmation , so i write a script like this </p>
  
  <pre><code> &lt;script&gt;
  
  function myFunction() {
    var txt;
    if (confirm("Do you want to delete!")) {
     window.location.href ='{% url 'polls:deleteuser' user_name=user.name %}';
    } else {
    //don't do anything
    }
  
  }
    &lt;/script&gt;
  
  </code></pre>
  
  <p>everytime i press ok it will error <code>Reverse for 'deleteuser' with keyword arguments '{'user_name': ''}' not found. 1 pattern(s) tried: ['deleteuseradmin/(?P&lt;user_name&gt;[^/]+)$']</code></p>
  
  <p>the window.location.href not working , maybe it cannot pass from the class value? i need help to fix it </p>
  
  <p>here's the url</p>
  
  <pre><code>path('deleteuseradmin/&lt;str:user_name&gt;',views.del_user,name='deleteuser'),
  </code></pre>
  
  <p>thankyou</p>
  
  <p>EDIT:
  VIEWS.PY</p>
  
  <pre><code>def del_user(request, user_name): 
      u = User.objects.get(username = user_name)      
      identity = u.id
      import cx_Oracle
      dsn_tns = cx_Oracle.makedsn('', '', sid='') 
      conn = cx_Oracle.connect(user=r'', password='', dsn=dsn_tns) 
      c = conn.cursor() 
      c.execute("delete from polls_userprofileinfo where user_id = '"+str(identity)+"'")
      conn.commit()
      c.execute("delete from auth_user where  id = '"+str(identity)+"'")
      conn.commit()
      messages.success(request, "The user is deleted")     
      print("sukses");
      return redirect('/manageuser/')
  </code></pre>
  
  <p>error trace</p>
  
  <pre><code>NoReverseMatch at /manageuser/
  Reverse for 'deleteuser' with arguments '('',)' not found. 1 pattern(s) tried: ['deleteuseradmin/(?P&lt;user_name&gt;[^/]+)$']
  Request Method: GET
  Request URL:    http://127.0.0.1:8000/manageuser/
  Django Version: 2.2.6
  Exception Type: NoReverseMatch
  Exception Value:    
  Reverse for 'deleteuser' with arguments '('',)' not found. 1 pattern(s) tried: ['deleteuseradmin/(?P&lt;user_name&gt;[^/]+)$']
  Exception Location: C:\Users\u532246\AppData\Local\Programs\Python\Python38\lib\site-packages\django\urls\resolvers.py in _reverse_with_prefix, line 673
  Python Executable:  C:\Users\u532246\AppData\Local\Programs\Python\Python38\python.exe
  Python Version: 3.8.0
  Python Path:    
  ['C:\\Users\\u532246\\Desktop\\django-master-terbaru-4\\django-master-terbaru3\\django-master-terbaru3\\Django-master',
   'C:\\Users\\u532246\\AppData\\Local\\Programs\\Python\\Python38\\python38.zip',
   'C:\\Users\\u532246\\AppData\\Local\\Programs\\Python\\Python38\\DLLs',
   'C:\\Users\\u532246\\AppData\\Local\\Programs\\Python\\Python38\\lib',
   'C:\\Users\\u532246\\AppData\\Local\\Programs\\Python\\Python38',
   'C:\\Users\\u532246\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages']
  Server time:    Tue, 7 Jan 2020 09:38:09 +0000
  Error during template rendering
  In template C:\Users\u532246\Desktop\django-master-terbaru-4\django-master-terbaru3\django-master-terbaru3\Django-master\polls\templates\manage_user.html, error at line 342
  
  Reverse for 'deleteuser' with arguments '('',)' not found. 1 pattern(s) tried: ['deleteuseradmin/(?P&lt;user_name&gt;[^/]+)$']
  332           }
  333         });
  334       });
  335       });
  336   &lt;/script&gt;
  337   &lt;script&gt;
  338 
  339 function myFunction() {
  340   var txt;
  341   if (confirm("Do you want to delete!")) {
  342    window.location.href ='{% url 'polls:deleteuser' user.name %}';
  343   } else {
  344   //don't do anything
  345   }
  346 
  347 }
  348   &lt;/script&gt;
  349 
  350 &lt;/body&gt;
  351 
  352 &lt;/html&gt;
  Traceback Switch to copy-and-paste view
  C:\Users\u532246\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\handlers\exception.py in inner
              response = get_response(request) …
  ▶ Local vars
  C:\Users\u532246\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\handlers\base.py in _get_response
                  response = self.process_exception_by_middleware(e, request) …
  ▶ Local vars
  C:\Users\u532246\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\handlers\base.py in _get_response
                  response = wrapped_callback(request, *callback_args, **callback_kwargs) …
  ▶ Local vars
  C:\Users\u532246\Desktop\django-master-terbaru-4\django-master-terbaru3\django-master-terbaru3\Django-master\polls\views.py in manageuser
              return render(request, 'manage_user.html',context) …
  ▶ Local vars
  C:\Users\u532246\AppData\Local\Programs\Python\Python38\lib\site-packages\django\shortcuts.py in render
      content = loader.render_to_string(template_name, context, request, using=using) …
  ▶ Local vars
  C:\Users\u532246\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\loader.py in render_to_string
      return template.render(context, request) …
  ▶ Local vars
  C:\Users\u532246\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\backends\django.py in render
              return self.template.render(context) …
  ▶ Local vars
  C:\Users\u532246\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py in render
                      return self._render(context) …
  ▶ Local vars
  C:\Users\u532246\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py in _render
          return self.nodelist.render(context) …
  ▶ Local vars
  C:\Users\u532246\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py in render
                  bit = node.render_annotated(context) …
  ▶ Local vars
  C:\Users\u532246\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py in render_annotated
              return self.render(context) …
  ▶ Local vars
  C:\Users\u532246\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\defaulttags.py in render
              url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app) …
  ▶ Local vars
  C:\Users\u532246\AppData\Local\Programs\Python\Python38\lib\site-packages\django\urls\base.py in reverse
      return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)) …
  ▶ Local vars
  C:\Users\u532246\AppData\Local\Programs\Python\Python38\lib\site-packages\django\urls\resolvers.py in _reverse_with_prefix
          raise NoReverseMatch(msg) …
  ▶ Local vars
  </code></pre>