Django reverse() for JavaScript

前端 未结 9 1086
情深已故
情深已故 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:51

    I have found this cool django app called Django JS reverse

    https://github.com/ierror/django-js-reverse

    If you have a url like

    url(r'^/betterliving/(?P[-\w]+)/(?P\d+)/$', 'get_house', name='betterliving_get_house'),
    

    Then you do

    Urls.betterliving_get_house('house', 12)
    

    The result is

    /betterliving/house/12/
    

提交回复
热议问题