views:

34

answers:

1

Hi, I'm using pyfacebook on the backend and javascript on the client side. Now if I want to pass a variable to the javascript from pyfacebook. how would I go about doing that, any ideas?

+1  A: 

You can't pass a variable directly, as JavaScript is running on the client (browser), and Python is running on the server. You could make a XHR (AJAX) request from JavaScript to the server which would then return your values back to JS (JSON could be used here). Or you could put a hidden field to your markup that would have the value in it's "value" attribute. You could then read that with JavaScript.

ps: your question really isn't related to pyfacebook but Python (or any other server side technology) in general and that has been covered here many many times.

Jan Hančič
I calculated the values I needed on the server side and through the render_to_response in django passed the variable to the script and it worked :)
Fahim Akhter