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 8388583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:30:05+00:00 2026-06-09T18:30:05+00:00

I know JSON to solve this problem, but I have problems in implementing it.

  • 0

I know JSON to solve this problem, but I have problems in implementing it. Here is the detail of my approach:

  1. Data are calculated in Python
  2. Since the size of data is dynamic, so I need to use JavaScript to create extra HTML table rows for my outputs. As a result, I need to pass data from Python to JavaScript to let Javascript to ‘see’ the data.

HTML Code (below is a section of my HTML code to create the output page):

class OutputPage(webapp.RequestHandler):
    def func (a,b):
        return a+b #just an example

    def get(self):
        form = cgi.FieldStorage() 
        chem_name = form.getvalue('chemical_name')
        Para1 = form.getvalue('Para1')  #get values from input page--user inputs
        Para1 = float(Para1)
        Para2 = form.getvalue('Para2')  #get values from input page--user inputs
        Para2 = float(Para2)
        out = func (Para1,Para1)
        out_json=simplejson.dumps(out)  # I need to send out to JavaScript
        #writ output page
        templatepath = os.path.dirname(__file__) + '/../templates/'
        html = html + template.render (templatepath + 'outputpage_start.html', {})
        html = html + template.render (templatepath + 'outputpage_js.html', {})               
        html = html + """<table width="500" class='out', border="1">
                          <tr>  
                            <td>parameter 1</td>
                            <td>&nbsp</td>                            
                            <td>%s</td>
                          </tr>
                          <tr>  
                            <td>parameter 2</td>
                            <td>&nbsp</td>                            
                            <td>%s</td>
                          </tr>                                                      
                          </table><br>"""%(Para1, Para2)
        html = html + template.render(templatepath + 'outputpage_end.html', {})
        #attempt to 'send' Python data (out_json) to JavaScript, but I failed.
        html = html + template.render({"my_data": out_json})  
        self.response.out.write(html)

app = webapp.WSGIApplication([('/.*', OutputPage)], debug=True)

JavaScript Code (I use JavaScript to create additional inputs tables on the fly filename:’outputpage_js.html’):

<script>
<script type='text/javascript'> 

$(document).ready(function(){
    //I assume if my Json statement works, I should be able to use the following argument to create a HTML row
    $('<tr><td>Parameter 2</td><td>&nbsp</td><td>out_json</td>').appendTo('.app')   

</script>    

Thanks for the help!

  • 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-06-09T18:30:07+00:00Added an answer on June 9, 2026 at 6:30 pm

    you don’t have to “implement” JSON, python comes with a built in lib, called simplejson, which you can feed with normal dicts:

    try: 
      import simplejson as json
    except:
      import json
    out = {'key': 'value', 'key2': 4}
    print json.dumps(out)
    

    EDIT:
    as tadeck pointed out, simplejson should be more up-to-date and is not equal to json, but there is a chance, simplejson is not available due to it is maintained externaly

    EDIT 2:
    based on the discussion in this answer and the discussion on the page, i think, the best approach would be something like that:

    python

    # [...] generate dynamic data [...]
    html = html + template.render (templatepath + 'outputpage_start.html', {})
    html = html + template.render (templatepath + 'outputpage_js.html', {})               
    html = html + """<table width="500" class='out' border="1" data-dynamic="%s">""" % json.dumps(your_generated_data_dict)
    #tr/td elements and templating as needet
    self.response.out.write(html)
    

    javascript

    $(function(){
        var your_generated_table = $('table'),
            dynamic_data = JSON.parse(your_generated_table.attr('data-dynamic'));
    });
    

    you then have the exact same structure your python dict has as a javascript object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i know im not the first with this problem, but i cant seem to
I have been trying to solve this problem for three days now, it's really
I'm sure you know this problem, I'm still trying to solve it for few
I know that this question might have been asked like 100 times, but, believe
I need help to solve this problem: I have a csv file like this
This seems to be a fairly common problem, but the solutions that I have
I followed other reslted question but still unable to solve this problem. I want
I know that Android has a JSON parser baked in but I was wondering
I would like to know how could I use JSON for passing data from
This is a question that I know has been asked here and several other

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.