Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6852941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:27:07+00:00 2026-05-27T01:27:07+00:00

I have been trying to make a page which combines web.py and JavaScript, and

  • 0

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.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:27:07+00:00Added an answer on May 27, 2026 at 1:27 am

    You can enable json encoder in template globals, and use it in your javascript code.

    import json
    template_globals = {"json_encode": json.dumps}
    render = web.template.render(config.template_dir, globals=template_globals, base="layout")
    

    Then in your template

    <script>
    var obj = $:json_encode({"html": getContents('http://mysite.net')});
    document.write(obj.html);
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to somehow get my javascript function (which I have in the
I have been developing a magazine engine which behaves like a web page. Currently
i have been trying very hard to make tinyMCE work on my page. even
I have been trying to make a case for using Python at my work.
I have been trying to make a div fade in evey 30sec and out
I have been trying to make the sub-menu horizontal. In my HTML it looks
I have been trying to make an init script using start-stop-daemon. I am stuck
I have been trying to make this to be a little jQuery plugin that
I have been trying to make a Cross-platform 2D Online Game, and my maps
I have been trying to test my application to make sure that all the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.