I have been trying to make a page which combines web.py and JavaScript, and with the following code:
$code:
def getContents(fname):
a = req.get(fname)
return a.content
<script type="text/javascript">
document.write("$getContents('http://mysite.net')");
</script>
Here, req is passed on my template’s $def with() function, being a module object of the Python Requests module, from which I execute methods.)
Problem is, the document is blank, which means the document.write function got no input. Is there a way around this? Am I doing this in a wrong way?
EDIT: The function output is not empty; if you use plain HTML to print it it will just work.
Thanks in advance.
(I’ve also posted this question on the web.py Google group, got no answer yet.)
You can enable json encoder in template globals, and use it in your javascript code.
Then in your template