views:

51

answers:

1

Hi, I have some sort of a design problem with my Django AJAX application.

I have a template where I initialize js variable from django context variable like so:

var test = "{{ test }}";

This variable is than used in a number of js functions that are needed for interface to work properly.

So now I'm trying to reuse some content from this page in another page that loads it dynamically on some user interaction using jQuery.load(..), and I don't see any way how I can initialize that variable, so js functions don't work now.

Is there any solution for this or may be I'm doing it wrong?

Thanks.

+2  A: 

Maybe you should include that variable in every page you want to use the js. Also, you may want to check Context Processors in django: http://docs.djangoproject.com/en/dev/ref/templates/api/

ign
Thank you very much, context processor will be a good solution for this case, but still there is a room for improvement because code will be duplicated whenever I want to use this variable in another app
dragoon