RSS

Blog

Django pluggable: jQuery integration

h325 May 2009 –  Comments (7)

Comments

this seems useless - although im glad you like it

[] uhm ~ 9 months, 2 weeks ago at 4:27 p.m.

Won't { jquery_urls } expose all urls? I'm not sure you want to do that?

[] Nix ~ 9 months, 2 weeks ago at 4:59 p.m.

how about just using the built-in url tag? http://docs.djangoproject.com/en/dev/topics/http/urls/#id2

[] Adrian ~ 9 months, 2 weeks ago at 6:38 p.m.

Adrian - presumably because he's doing this in a static JS file, not a template.

But Nix's point is valid. I use a different method - I create an attribute like 'data-callback-url="{% url callback-url-name %}"' on an HTML element, then use $(this).attr("data-callback-url") to get the URL in JS code.

[] Adam Gomaa ~ 9 months, 2 weeks ago at 8:27 a.m.

@Nix:

That's a valid concern and should be considered when using it in a project.

@Adrian:

The built-in URL tag works fine for parameter-less URLs, but there is some downsides;

  • You must interpret your JS file as template, so you cannot serve it statically
  • You'll hit a brick wall when you'll need an URL which requires some parameters
  • You have to mix template code with your JS, not a big deal but still annoying
  • You cannot minify your JavaScript

I'm glad I've posted this code since Nix's point and Adam's trick will probably bring some positive changes in my code.

Thanks for you feedback guys

[] h3 ~ 9 months, 2 weeks ago at 11:02 a.m.

Pretty cool project, I usually doing stuff like @Adam Gomaa

[] Vitaly Babiy ~ 9 months ago at 1:47 p.m.

Nice project, I hit the same wall when I split my code into more modules all ajax named urls broke. I would use this app if it weren't for the security concern.

[] Robert ~ 4 months, 3 weeks ago at 12:04 p.m.

Copyrighted stuff .. u know.