title: Reverse for 'edit-expense' with no arguments not found. 1 pattern(s) tried: ['edit\\-expense/(?P<id>[0-9]+)$'] - Django
body: <p>Trying to display a Page to update record but receiving following error.</p>
  <p><strong>ERROR</strong></p>
  <pre><code>NoReverseMatch at /edit-expense/2
  Reverse for 'edit-expense' with no arguments not found. 1 pattern(s) tried: ['edit\\-expense/(?P&lt;id&gt;[0-9]+)$']
  Request Method: GET
  Request URL:    http://127.0.0.1:8000/edit-expense/2
  Django Version: 3.2.5
  Exception Type: NoReverseMatch
  Exception Value:    
  Reverse for 'edit-expense' with no arguments not found. 1 pattern(s) tried: ['edit\\-expense/(?P&lt;id&gt;[0-9]+)$']
  Exception Location: C:\Users\Ideation\AppData\Roaming\Python\Python39\site-packages\django\urls\resolvers.py, line 694, in _reverse_with_prefix
  Python Executable:  C:\Program Files\Python39\python.exe
  Python Version: 3.9.5
  Python Path:    
  ['C:\\xampp\\htdocs\\Projects\\Ideation\\Ideation',
   'C:\\Users\\Ideation\\AppData\\Roaming\\Python\\Python39\\site-packages\\_pdbpp_path_hack',
   'C:\\Program Files\\Python39\\python39.zip',
   'C:\\Program Files\\Python39\\DLLs',
   'C:\\Program Files\\Python39\\lib',
   'C:\\Program Files\\Python39',
   'C:\\Users\\Ideation\\AppData\\Roaming\\Python\\Python39\\site-packages',
   'C:\\Users\\Ideation\\AppData\\Roaming\\Python\\Python39\\site-packages\\win32',
   'C:\\Users\\Ideation\\AppData\\Roaming\\Python\\Python39\\site-packages\\win32\\lib',
   'C:\\Users\\Ideation\\AppData\\Roaming\\Python\\Python39\\site-packages\\Pythonwin',
   'C:\\Program Files\\Python39\\lib\\site-packages']
  Server time:    Fri, 27 Aug 2021 05:30:22 +0000
  </code></pre>
  <p><strong>views.py</strong></p>
  <pre><code>from django.shortcuts import render, redirect
  from django.contrib.auth.decorators import login_required
  from django.contrib import messages
  
  from .models import Category, Expense
  
  @login_required(login_url = &quot;login&quot;)
  def expense_edit(request, id):
      expense = Expense.objects.get(pk=id)
      context = {
          'expense': expense,
          'values': expense,
      }
      if request.method == 'GET':
          return render(request, 'expenses/edit_expense.html', context)
  
      # if request.method == &quot;POST&quot;:
      else:
          messages.add_message(request, messages.INFO, 'Handling post form')
          return render(request, 'expenses/edit_expense.html', context)
  </code></pre>
  <p><strong>urls.py</strong></p>
  <pre><code>from django.urls import path
  from . import views
  
  urlpatterns = [
      path('', views.index, name=&quot;index&quot;),
      path('add-expense', views.add_expense, name=&quot;add-expense&quot;),
      path('edit-expense/&lt;int:id&gt;', views.expense_edit, name=&quot;edit-expense&quot;),
  ]
  </code></pre>
  <p><strong>edit_expense.html</strong></p>
  <pre><code>{% extends 'base.html' %}
  
  {% block content %}
  
  &lt;div class=&quot;container mt-4&quot;&gt;
  
      &lt;h2&gt;Edit Expense&lt;/h2&gt;
  
      &lt;nav aria-label=&quot;breadcrumb&quot;&gt;
          &lt;ol class=&quot;breadcrumb&quot;&gt;
              &lt;li class=&quot;breadcrumb-item&quot;&gt;&lt;a href=&quot;{% url 'index' %}&quot;&gt;Expenses&lt;/a&gt;&lt;/li&gt;
              &lt;li class=&quot;breadcrumb-item active&quot; aria-current=&quot;page&quot;&gt;Edit Expense&lt;/li&gt;
          &lt;/ol&gt;
      &lt;/nav&gt;
  
  
  
      &lt;div class=&quot;card&quot;&gt;
          &lt;div class=&quot;card-body&quot;&gt;
              &lt;form action=&quot;{% url 'edit-expense' %}&quot; method=&quot;POST&quot;&gt;
                  {% csrf_token %}
                  {% include 'partials/_messages.html' %}
                  &lt;div class=&quot;form-group&quot;&gt;
                      &lt;label for=&quot;amountvalue&quot;&gt;Amount&lt;/label&gt;
                      &lt;input value=&quot;{{values.amount}}&quot; type=&quot;number&quot; class=&quot;form-control-sm form-control&quot; name=&quot;amount&quot;
                          id=&quot;amountvalue&quot;&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;form-group&quot;&gt;
                      &lt;label for=&quot;descriptionvalue&quot;&gt;Description&lt;/label&gt;
                      &lt;input value=&quot;{{values.description}}&quot; type=&quot;text&quot; class=&quot;form-control-sm form-control&quot;
                          name=&quot;description&quot; id=&quot;descriptionvalue&quot;&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;form-group&quot;&gt;
                      &lt;label for=&quot;categoryvalue&quot;&gt;Category&lt;/label&gt;
                      &lt;select name=&quot;category&quot; id=&quot;categoryvalue&quot; class=&quot;form-control-sm form-control&quot;&gt;
                          {% for category in categories %}
                          &lt;option value=&quot;{{category.name}}&quot;&gt;{{category.name}}&lt;/option&gt;
                          {% endfor %}
                      &lt;/select&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;form-group&quot;&gt;
                      &lt;label for=&quot;dateofexpensevalue&quot;&gt;Date of Expense&lt;/label&gt;
                      &lt;input value=&quot;{{values.date}}&quot; type=&quot;date&quot; class=&quot;form-control-sm  form-control&quot; name=&quot;expense_date&quot;
                          id=&quot;dateofexpensevalue&quot;&gt;
                  &lt;/div&gt;
                  &lt;input type=&quot;submit&quot; value=&quot;Update&quot; class=&quot;btn btn-primary mt-2&quot;&gt;
              &lt;/form&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  
  
  
  
  &lt;/div&gt;
  
  {% endblock content %}
  </code></pre>
  <p><strong>index.html</strong></p>
  <pre><code>{% extends 'base.html' %}
  
  {% block content %}
  &lt;div class=&quot;container-fluid mt-4&quot;&gt;
  
      &lt;div class=&quot;row&quot;&gt;
          &lt;!-- &lt;h2&gt;Expenses List&lt;/h2&gt; --&gt;
  
          &lt;div class=&quot;col-md-10&quot;&gt;
              &lt;nav aria-label=&quot;breadcrumb&quot;&gt;
                  &lt;ol class=&quot;breadcrumb&quot;&gt;
                      &lt;li class=&quot;breadcrumb-item&quot;&gt;&lt;a href=&quot;#&quot;&gt;Expenses&lt;/a&gt;&lt;/li&gt;
                      &lt;li class=&quot;breadcrumb-item active&quot; aria-current=&quot;page&quot;&gt;My Expenses&lt;/li&gt;
                  &lt;/ol&gt;
              &lt;/nav&gt;
          &lt;/div&gt;
  
  
          &lt;div class=&quot;col-md-2&quot;&gt;
              &lt;a href=&quot;{% url 'add-expense' %}&quot; class=&quot;btn btn-primary&quot;&gt;Add Expense&lt;/a&gt;
          &lt;/div&gt;
  
      &lt;/div&gt;
      &lt;br&gt;
      {% include 'partials/_messages.html' %}
      {% if expenses.count %}
      &lt;!-- &lt;div class=&quot;container-fluid&quot;&gt;&lt;/div&gt; --&gt;
      &lt;table class=&quot;table table-stripped table-hover mt-4&quot;&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th&gt;Amount ($)&lt;/th&gt;
                  &lt;th&gt;Category&lt;/th&gt;
                  &lt;th&gt;Description&lt;/th&gt;
                  &lt;th&gt;Date&lt;/th&gt;
                  &lt;th&gt;&lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
              {% for expense in expenses %}
              &lt;tr&gt;
                  &lt;td&gt;{{expense.amount}}&lt;/td&gt;
                  &lt;td&gt;{{expense.category}}&lt;/td&gt;
                  &lt;td&gt;{{expense.description}}&lt;/td&gt;
                  &lt;td&gt;{{expense.date}}&lt;/td&gt;
                  &lt;td&gt; &lt;a href=&quot;{% url 'edit-expense' expense.id %}&quot; class=&quot;btn btn-secondary btn-sm&quot;&gt;Edit&lt;/a&gt; &lt;/td&gt;
              &lt;/tr&gt;
              {% endfor %}
          &lt;/tbody&gt;
      &lt;/table&gt;
      &lt;!-- &lt;/div&gt; --&gt;
      {% endif %}
  
  
  &lt;/div&gt;
  
  
  
  {% endblock content %}
  </code></pre>
  <p><strong>CODE EXPLANATION</strong></p>
  <p><strong>- VIEWS</strong></p>
  <ul>
  <li>First of all login to <code>edit_expense.html</code> is required.</li>
  <li>Then getting record from database with the id.</li>
  <li>Then, creating context in which first we expense record and values which contain expense record as well which will be used to display in the HTML form for updating.</li>
  <li>After this, rendering template.</li>
  <li>Right now values are not taken from <code>edit_expense.html</code>, we are only displaying it.</li>
  </ul>
  <p><strong>- URLS</strong></p>
  <ul>
  <li>Simply adding url.</li>
  </ul>
  <p><strong>- EDIT EXPENSE</strong></p>
  <ul>
  <li>Extending base template which contains things like normally all the base.html contains.</li>
  <li>Then in <code>block</code> template tag adding breadcrumb, after that a card which contains a HTML form.</li>
  <li>In HTML form, only <code>_messages.html</code> is only to display different messages which is additinal and rest of things basic HTML and some bootstrap.</li>
  </ul>
  <p><strong>INDEX</strong></p>
  <ul>
  <li>It is to display records which is showing everything normally.</li>
  </ul>