> Weird, I have missed this thread. But anyway, like sdcooke, that's > also the way that we handle URLs in javascript. > Attach a data attribute to the HTML node to which it applies, and read > it from inside the javascript. It's clean. > > <td><a href="{% url accounts_edit_name %}" > x:ajax-url="{% url accounts_ajax_edit_name %}">{% trans "Edit" %}</ > a></td> > > Like gettext, a seperate, dynamically generated javascript file for > URL resolving is not scalable to lange web applications. > And further, I think that the urls and names of views are not meant to > be exposed to the client. I don't want a visitor to be able to reverse > engineer my website, and read all the possible URL patterns. > > Jonathan
Just sharing thought here. Another approach that I use is creating an "indirect" url and view that reads the url_name and args from request.REQUEST, reverse the path, resolve the view and call it on your behalf. ## urls.py # from django.conf.urls.defaults import patterns, url urlpatterns = patterns('js.views', url(r'^url_reverse/$', 'url_reverse', name='js_url_reverse'), ) ## views.py # from django import http from django.core import urlresolvers def url_reverse(request): if request.method in ('GET', 'POST'): data = getattr(request, request.method) url_name = data.get('url_name') try: path = urlresolvers.reverse(url_name, args=data.getlist('args')) (view_func, args, kwargs) = urlresolvers.resolve(path) return view_func(request, *args, **kwargs) except urlresolvers.NoReverseMatch: raise http.Http404 return http.HttpResponseNotAllowed(('GET', 'POST')) Somewhere in javascript: $.get('/js/url_reverse/', { url_name: "account_profile", args: [username]}); Of cause, this approach exposes your url names to javascript. Some people might not like it. -- 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.