Django reverse() for JavaScript

前端 未结 9 1080
情深已故
情深已故 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条回答
  •  暖寄归人
    2020-12-24 07:49

    Try creating javascript helper functions (in django template) for generating url string. In simple form they could look like this:

    function generete_some_url(id){
        return "{% url some_url itemid=112233 %}".replace("112233", id);
    }
    

    Maybe this has some other implications but I think it should work.

提交回复
热议问题