在Django中找不到网址

时间:2018-01-04 12:47:45

标签: python ajax django

我有一个ajax调用如下:

function getBodyHeights(seats_id) {
    $('[data-body-length]').html(gettext("Body length"));
    $('[data-weights]').html(gettext("Weights"));
    $('[data-wheel-drive]').html(gettext("Wheel drive"));
    $('[data-transmission]').html(gettext("Transmission"));
    $('[data-trim]').html(gettext("Trim Level"));
    $.ajax({
        type: 'GET',
        url: '/master/heights/' + seats_id,
        success: function (data) {
            removeActiveClass();
            $('#content').html(data)
        },
        error: function (error) {
            $('#body-heights-error').removeClass('hidden').html(error.responseText)
        }
    })
}

在根文件夹中我有:

urlpatterns = [
   ....
   url(r'^master/', include('master.urls')),
   ...
]

在urls.py的主文件夹中,我有如下

urlpatterns = [
   ....
   url(r'^facelifts/(\d+)/$', views_data.facelifts, name='facelifts'),
   url(r'^seats/(\d+)/$', views_data.seats, name='seats'),
   url(r'^heights/(\d+)/$', views_data.body_heights, name='heights'),
   ...
]

但是当我尝试在点击时执行ajax调用时出现错误:

enter image description here

更新

function getFacelifts(body_id) {
    $('[data-seats]').html(gettext("Seats"));
    $('[data-body-height]').html(gettext("Body height"));
    $('[data-body-length]').html(gettext("Body length"));
    $('[data-weights]').html(gettext("Weights"));
    $('[data-engine]').html(gettext("Engine"));
    $('[data-wheel-drive]').html(gettext("Wheel drive"));
    $('[data-transmission]').html(gettext("Transmission"));
    $('[data-trim]').html(gettext("Trim Level"));
    $.ajax({
        type: 'GET',
        url: '/master/facelifts/' + body_id,
        success: function (data) {
            removeActiveClass();
            $('#content').html(data)
        },
        error: function (error) {
            $('#facelifts-error').removeClass('hidden').html(error.responseText)
        }
    })
}

function getSeats(facelift_id) {
    $('[data-body-height]').html(gettext("Body height"));
    $('[data-body-length]').html(gettext("Body length"));
    $('[data-weights]').html(gettext("Weights"));
    $('[data-engine]').html(gettext("Engine"));
    $('[data-wheel-drive]').html(gettext("Wheel drive"));
    $('[data-transmission]').html(gettext("Transmission"));
    $('[data-trim]').html(gettext("Trim Level"));
    $.ajax({
        type: 'GET',
        url: '/master/seats/' + facelift_id,
        success: function (data) {
            removeActiveClass();
            $('#content').html(data)
        },
        error: function (error) {
            $('#seats-error').removeClass('hidden').html(error.responseText)
        }
    })
}

1 个答案:

答案 0 :(得分:0)

我有同样的问题,请尝试更改:

url: '/master/heights/' + seats_id,

为此:

url: '/master/heights/' + seats_id + '/',

Ajax到django是如此严格