在Django的Javascript干网址 [英] DRY URLs in Django Javascript
问题描述
我使用Django的AppEngine上。我使用Django的反向()
功能无处不在,保持原有的一切尽可能的干燥。
不过,我在此应用到我的客户端JavaScript的麻烦。有加载一些数据取决于传入的ID的JS类。有没有一个标准的办法不硬code中的URL,这个数据应该来自哪里?
VAR RQ =新Request.HTML({
更新:this.element,
})得到('/模板/+ template_id +'/ preVIEW')。 //困扰我的一部分。
最合理的解决方案似乎是通过URL列表中的JavaScript文件,并具有相当的JavaScript的反向的()可在客户端上。唯一的反对意见可能是整个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.
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干网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!