how to pass kwargs in ajax urls in django? Reverse for ” with arguments ‘(”,)’ not found. 1 pattern tried: [‘partners/analytics/(?P[0-9]+)/$’]

I have the following code in one of my templates:

      var id = "{{a.id}}";

$.ajax({
                url :'{% url 'this:dashboard' id %}',,
                type : 'POST',
                data : {
                    

                },      
            });

I get the following error?

Reverse for '' with arguments '('',)' not found. 1 pattern(s) tried: ['dash/here/(?P<id>[0-9]+)/$']


my url is:

    path('here/<int:id>/', views.dashboard, name="dashboard"),

Answer

Change

url :'{% url 'this:dashboard' id %}',,

To

url :'{% url 'this:dashboard' a.id %}',

The issue with your code is, the templates are rendered in the server and the var id gets its value only after being executed in the client slide that’s why you are getting URL error.