Raise NoReverseMatch(msg) django.urls.exceptions.NoReverseMatch: Обратный запрос для 'generate_payroll' без аргументов не найден

вот мой views.py

def qualified(request, employee_id):
    current_date = datetime.date.today()
    _history = PayrollModel.objects.all()
    for her in _history:
        if(her.employee_id_id == employee_id):
            # mnt = her
            if((current_date.month != her.month_year.month
                and current_date.month > her.month_year.month)
               and current_date.year == her.month_year.year):
                return messages.success(request, "HAPPY BD")
            else:
                return messages.success(request, "SAD BD")


def generate_payroll(request, employee_id):

    qualification = qualified(request, employee_id=employee_id)
    current_date = datetime.date.today()

    if (qualification == True):

        overTimeValue = calculate_overtime(employee_id)
        allowanceValue = calculate_allowance(employee_id)
        bonusValue = calculate_bonus(employee_id)
        employee = EmployeeModel.objects.get(pk=employee_id)
        salary = PayGradeModel.objects.get(pk=employee.basic_salary_id)
        ssf = calculate_ssf(salary)
        netValue = (float(salary.amount) + float(overTimeValue) +
                    float(bonusValue) + float(allowanceValue)) - float(ssf)  # allowanceValue
        payroll = PayrollModel.objects.create(employee_id_id=employee_id)
        payroll.month_year = current_date
        payroll.basicSalary = salary.amount
        payroll.ssf_deduction = float(ssf)
        payroll.over_time = float(overTimeValue)
        payroll.bonus = float(bonusValue)
        payroll.allowance = allowanceValue
        payroll.gross_pay = salary.amount
        payroll.net_salary = float(netValue)
        payroll.save()
        messages.success(request, 'payroll generated successfully')
        return HttpResponseRedirect('/get_payroll')
    else:
        #     payrolls = PayrollModel.objects.filter(employee_id_id=employee_id)
        return render(request, 'payrolls/get_payroll.html', {'payrolls': payroll}

models.py

class PayrollModel(models.Model):
    month_year = models.DateField(null=True)
    # month_year = MonthField(
    #     "Month value", help_text="some help...", null=True)
    gross_pay = models.CharField(max_length=100, null=True)
    bonus = models.CharField(max_length=100, null=True)
    allowance = models.CharField(max_length=100, null=True)
    ssf_deduction = models.CharField(max_length=100, null=True)
    over_time = models.CharField(max_length=100, null=True)
    net_salary = models.CharField(max_length=100, null=True)
    employee_id = models.ForeignKey(
        EmployeeModel, on_delete=models.CASCADE, null=True)
    date_created = models.DateTimeField(auto_now_add=True, null=True)
    updated = models.DateTimeField(auto_now=True, null=True)

    class Meta:
        db_table = 'payrolls'
        ordering = ['-updated', '-date_created']

urls.py

path('employees/<int:pk>/payrolls/generate_payroll',
         views.generate_payroll, name='generate_payroll'),

get_payroll.html

.id"></a>
</button>



<br>
<h4>Payroll for {{ payrolls.first.employee_id.first_name}} {{ payrolls.first.employee_id.last_name }}</h4>
<table class="table">
    <thead>
        <tr>

            <th scope="col">Payroll Month</th>
            <th scope="col">Gross Pay</th>
            <th scope="col">Allowances</th>
            <th scope="col">Bonus</th>
            <th scope="col">Overtime</th>
            <th scope="col">Social Security</th>
            <th scope="col">Net salary</th>
            <th scope="col">Payslip</th>
        </tr>
    </thead>
    <tbody>
        {% for payroll in payrolls %}
        <tr>
            <td>{{ payroll.month_year }}</td>
            <td>{{ payroll.gross_pay }}</td>
            <td>{{ payroll.allowance }}</td>
            <td>{{ payroll.bonus }}</td>
            <td>{{ payroll.over_time }}</td>
            <td>{{ payroll.ssf_deduction }}</td>
            <td>{{ payroll.net_salary }}</td>

            <td><a href="{{ payroll.date_created.month }}/payslip" target="_blank" class="btn btn-info">Get payslip</a></td>



        </tr>
        {% endfor %}
    </tbody>

</table>
{% endblock %}

Я хочу архивировать, когда пользователь нажимает на кнопку generate payroll должна возбуждаться функция **generate_payroll и сохранять результат в db. в кнопке на моих шаблонах я передаю этот url <a href="{% url 'payrolls:generate_payroll' %} employees.id"></a> но я продолжаю получать ошибку django.urls.exceptions.NoReverseMatch: Обратный запрос для 'generate_payroll' без аргументов не найден. Проверен 1 шаблон(ы): ['employees/(?P[0-9]+)/payrolls/generate_payroll\Z']

Вам необходимо добавить параметр для URL's.

Обратитесь https://docs.djangoproject.com/en/4.0/ref/templates/builtins/#url

В шаблоне попробуйте следующее

<td>
    <a href="{% url 'generate_payroll' employees.id %}" target="_blank" class="btn btn-info">Get payslip</a>
</td>

В вашем представлении добавьте следующее

from django.core.urlresolvers import reverse

payroll.save()
messages.success(request, 'payroll generated successfully')
url = reverse('generate_payroll', kwargs={'pk': employees.id})
return HttpResponseRedirect(URL)
Вернуться на верх