Using Pylons Global Variables With JavaScript (escaping Brackets)
Solution 1:
I'm making a few (reasonable) assumptions here…
- Your Python is running on your webserver
- Your JavaScript is running on your client
As far as the Python is concerned it is outputting text. It doesn't care that the browser might interpret it as HTML, JavaScript or whatever. It just generates some text and then sends it to the browser.
With HTTP you get to make a request and have a response. You cannot stop a response half way through to get data back from the client.
You cannot pass data from client side JS back to the Python process that generated the JS. That process will have finished running.
You can either:
- Send all the data to the client in the first place (and then select the bits you want in JS instead of in Python)
- Have the JavaScript make a new HTTP request to the server and process the response in JS (this is known as Ajax and there are no shortage of tutorials out there for this)
Solution 2:
I don't know what execution environment you are using,but I am almost certain that python and javascript are not executing at the same time.
${c.persons_by_permission['stringID']}
looks to me like some kind of template directive. If so, this works because the directive is processed at template processing time. Your other form is just an expression in javascript that evaluates in javascript to a string.
Post a Comment for "Using Pylons Global Variables With JavaScript (escaping Brackets)"