0

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.

1 Answer 1

2

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/

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.