web.py and JavaScript issues

86 views
Skip to first unread message

theiostream

unread,
Nov 23, 2011, 5:44:11 PM11/23/11
to web.py
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>

(Where req is passed on my template's $def with(), being a module
object of the Python Requests (http://python-requests.org), 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?

Thanks in advance,
~ theiostream.

michael kapelko

unread,
Nov 24, 2011, 2:51:52 AM11/24/11
to we...@googlegroups.com
try to first do it without JS, just print $getContents at server side
with web.py only. may be it's simply empty.

theiostream

unread,
Nov 24, 2011, 5:47:39 AM11/24/11
to web.py
It's not. It works outside JavaScript.

Alice Atlas

unread,
Nov 24, 2011, 6:26:06 AM11/24/11
to we...@googlegroups.com
Could you post the source of the rendered page as seen in your browser? If $getContents() is working correctly when used outside of JavaScript code, my best guess is that this is an escaping issue. e.g. if the page you're retrieving contains a double quote anywhere.



On Thursday, November 24, 2011 5:47:39 AM UTC-5, theiostream wrote:
It's not. It works outside JavaScript.

Tom

unread,
Nov 24, 2011, 7:05:56 AM11/24/11
to web.py
What should the content be? If it's more than text, don't forget to
add the colon: $:getContents('htttp://mysite.net')

theiostream

unread,
Nov 24, 2011, 9:21:50 AM11/24/11
to web.py
I tried the $:. It keeps not displaying, and then gives me escaping
issues.

theiostream

unread,
Nov 24, 2011, 9:22:30 AM11/24/11
to web.py
Here is the quoted part of the source code: http://pastie.org/2914370.
It renders http://matoe.co.cc/patcher.txt. As far as I can see there
is no escaping issue :(

Alice Atlas

unread,
Nov 25, 2011, 2:44:21 AM11/25/11
to we...@googlegroups.com
Oh, looks like you just need to replace newlines in the string with \n.
Reply all
Reply to author
Forward
0 new messages