??yy 2010-04-27 19:30 采纳率: 0%
浏览 42

Django Javascript中的DRY URL

I'm using Django on Appengine. I'm using the django reverse() function everywhere, keeping everything as DRY as possible.

However, I'm having trouble applying this to my client-side javascript. There is a JS class that loads some data depending on a passed-in ID. Is there a standard way to not-hardcode the URL that this data should come from?

var rq = new Request.HTML({
    'update':this.element,
}).get('/template/'+template_id+'/preview'); //The part that bothers me.
  • 写回答

9条回答 默认 最新

  • weixin_33724659 2011-10-07 21:21
    关注

    The most reasonable solution seems to be passing a list of URLs in a JavaScript file, and having a JavaScript equivalent of reverse() available on the client. The only objection might be that the entire URL structure is exposed.

    Here is such a function (from this question).

    评论

报告相同问题?