noio noio - 6 months ago 67
Ajax Question

DRY URLs in Django Javascript

I'm using Django on Appengine. I'm using the django

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({
}).get('/template/'+template_id+'/preview'); //The part that bothers me.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download