I don't really know how to approach this issue the best way, so I'm
just going to be direct, I'd love to see Django provide support for
django.core.urlresolvers.reverse (at least) on the client (in
JavaScript).


I'm pretty sure all who have needed to make AJAX queries have dealt
with the issue of "where do we store our urls". The urls are, I'd
guess, 99% of the time, defined in Django, and I think that it usually
comes down to two approaches:
1) hard-code them: $.post("/hello/" + what + "/")
2) Store them in a variable or object: var hello_url = "{% url
hello_url what.id %}" - But if you need to "generate" the url based on
an id, this doesn't work.

There are more solutions of course, but these are the quick and easy
and I assume it's what most people use, and yes, it's just not elegant
and DRY.


What I'd like to propose to fix it:

1) Create a django namespace in JavaScript
2) Create a django.urls module, and implement reverse (and maybe
resolve)
3) Create a way to load urls from Django into JavaScript's django.urls
module (as django.urls.url_list or whatever) - of course, we don't
want all urls to be listed.


So my question is, is there any interest in getting something like
this into Django itself?

I think that with staticfiles bundling JavaScript for use outside of
the admin is possible and easy, but I also understand it's a sensible
matter even thou this wouldn't require any external libraries. I do
have an implementation of a urls module (https://github.com/mlouro/
olivejs/blob/master/olive/urls/urls.js) and tests (https://github.com/
mlouro/olivejs/blob/master/tests/urls.js), but it has a lot more stuff
attached that would be out of scope, as I think the urls themeselves
are a really important bit that Django should make available on the
client-side.


Thanks,
Marco

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to