Django Javascript中的DRY URL [英] DRY URLs in Django Javascript

查看:97
本文介绍了Django Javascript中的DRY URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Appengine上使用Django。我正在使用django reverse()函数,尽可能使所有内容都尽可能干。



然而,我我无法将此应用到我的客户端JavaScript。有一个JS类根据传入的ID加载一些数据。有没有一个标准的方法来对这个数据来源的URL进行硬编码?

  var rq = new Request.HTML {
'update':this.element,
})。get('/ template /'+ template_id +'/ preview'); //打扰我的部分


解决方案

最合理的解决方案似乎是传递一个JavaScript文件中的URL,并且具有JavaScript等效于客户端上的reverse()。唯一的反对可能是整个网址结构被暴露。



这是一个功能

a>(来自此问题)。


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.

解决方案

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).

这篇关于Django Javascript中的DRY URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆