AJAX not working on Django and returning 500 Error

I'm trying to send an AJAX request from my template that takes you to a url and runs the view function. However, I'm getting a 500 Error in my console. The error in Django log says: TypeError: delete_appointment() missing 1 required positional argument: 'appointment_id' My view is also using a custom decorator, all required code is below:


def user_has_delete(func, redirect_url="Home:Deny"):
    def wrapper(request, *args, **kwargs):
        if request.user.is_anonymous:
            return redirect(redirect_url)
        if request.user.is_authenticated:
            if not request.user.is_denier:
                return redirect(redirect_url)
                return func(request, *args, **kwargs)
    return wrapper

URL Pattern

path('Vet/DenyAppointment/<int:appointment_id>', views.delete_appointment)


def delete_appointment(request, appointment_id):
    appointment = get_object_or_404(Appointments, pk=appointment_id)
    return redirect('Dashboard')

Template Portion

{% for appointment in appointments %}
                        <div class="col-sm-12 col-lg-8 AppointmentDiv offset-sm-0 offset-lg-2 Space-b-sm">
                            <h2>{{ appointment.fullDate }}</h2>
                                    <li>{{ appointment.title }}</li>
                                    <li>{{ appointment.day }}</li>
                            <button type="submit" class="theme" id='{{ appointment.id }}' onclick="deleteAppointment({{ appointment.id }})">Delete Appointment</button>
                    {% endfor %}


            function deleteAppointment(appointmentId) {
                    url: '/Vet/DenyAppointment/' + appointmentId,
                    type: 'GET',
                    success: function(response) {
                        window.location.href = "/Dashboard";

Fixed. I wasn't sending data in my AJAX just appending the appointment id in url. Then I needed to configure my decorator to accept additional parameters.

Back to Top