title: Django execute a custom function from Admin
body: <p>I am new to Django and have gone through the <a href="https://docs.djangoproject.com/en/2.0/intro/tutorial01/" rel="nofollow noreferrer">first Django App</a> tutorial.I understand the separate bits but am not able to form a complete solution.</p>
  
  <p>My requirement is to add a custom button to a Model's Change List Page in Admin, redirect it to a confirmation page, execute a function on confirmation and then redirect to the change list page with execution status.</p>
  
  <p>I have added the custom button but am lost after that. 
  Currently this is what I am doing:</p>
  
  <p>Changed the admin class list template</p>
  
  <pre><code>class ReconciliationAdmin(admin.ModelAdmin):
      change_list_template = 'SalesReconciliation/change_list.html'
  </code></pre>
  
  <p>This is my change list template:</p>
  
  <pre><code>{% extends "admin/change_list.html" %}
  {% load i18n admin_static %}
  
  {% block object-tools-items %}
  {{ block.super }}
  &lt;li&gt;
      &lt;a href={% url 'admin:reconcileConfirm'%} class="btn btn-high btn-success"&gt;Run Reconciliation&lt;/a&gt;
  &lt;/li&gt;
  {% endblock %}
  </code></pre>
  
  <p>Changed the <strong>urls.py</strong> in the main app as follows:</p>
  
  <pre><code>urlpatterns = [
      url(r"^reconcileConfirm/", include("SalesReconciliation.urls")),
  ]
  </code></pre>
  
  <p>Changed the <strong>urls.py</strong> in the child app as follows:</p>
  
  <pre><code>urlpatterns = [
      url(r'^reconcileConfirm/', views.ReconcileConfirm, name='ReconcileConfirm')
  ]
  </code></pre>
  
  <p>In the <strong>views.py</strong> of the child app added the follows:</p>
  
  <pre><code>def ReconcileConfirm(request):
      return HttpResponse("..something")
  </code></pre>
  
  <p>I am hoping that this would work like:</p>
  
  <blockquote>
    <p>Click on Run Reconciliation link -> Main urls.py routes to child
    urls.py -> child urls.py routes to views.py -> function in views py
    performs some operations</p>
  </blockquote>
  
  <p>But I am getting the following errors:</p>
  
  <blockquote>
    <p>NoReverseMatch at /SalesReconciliation/reconciliation/ Reverse for 'reconcileConfirm' not found. 'reconcileConfirm' is not a valid view function or pattern name. </p>
    
    <p>Request Method: GET</p>
    
    <p>Request URL: <a href="http://127.0.0.1:8000/SalesReconciliation/reconciliation/" rel="nofollow noreferrer">http://127.0.0.1:8000/SalesReconciliation/reconciliation/</a></p>
    
    <p>Django Version: 2.0.4</p>
    
    <p>Exception Type: NoReverseMatch</p>
    
    <p>Exception Value: Reverse for 'reconcileConfirm' not found.</p>
    
    <p>'reconcileConfirm' is not a valid view function or pattern name.</p>
  </blockquote>
  
  <p>Also I would like to know whether it is the correct approach.</p>