user2492364
user2492364

Reputation: 6713

How to pase django urlname to a javascript in the template

I am trying to use url:"{% url 'final-result' %}", in my template so that my javascript can use that in an ajax call.

I got Reverse for 'final_result' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

Here is my ajax:

$(".score_statics").click(function(){
    var name = $(this).attr("data-name");
    $.ajax({
        url:"{% url 'final-result' %}",
        type: 'POST',
        async: false,
        dataType: 'json',
        data: {
            'name':name
        },
        success: function(dataArr){

        },
    });

And this is my url pattern

url(r'^score/result/$', views.final_result, name='final-result'),  

And my views.py

def final_result(request):
    if request.is_ajax():
    ...

    return JsonResponse({ "PASS"})

Do I have anything unset or uninstalled ?

Upvotes: 0

Views: 169

Answers (1)

Patrick Beeson
Patrick Beeson

Reputation: 1695

You're likely using namespaced urls: https://docs.djangoproject.com/en/1.9/topics/http/urls/#url-namespaces.

Try finding the namespace, then adjusting your template tag to {% url "namespace:final-result" %}

Upvotes: 2

Related Questions