Django reverse() for JavaScript

前端 未结 9 1073
情深已故
情深已故 2020-12-24 07:24

In my project I have a lot of Ajax methods, with external client-side scripts (I don\'t want to include JavaScript into templates!) and changing URLs is kind of pain for me

9条回答
  •  旧时难觅i
    2020-12-24 08:04

    You can remove the parameters from the URL, and pass the dynamic parts as query parameters:

      $('#add-choice-button').on('click', function () {
        var thing_id = $(this).closest('.thing').attr('data-item-id');
        $.get('{% url 'addThing' %}?t='+thing_id, function (data) {
          ...
        });
      });
    

提交回复
热议问题