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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:26:30+00:00 2026-06-18T15:26:30+00:00

I am building a pyramid/python app where my view callable for a certain template

  • 0

I am building a pyramid/python app where my view callable for a certain template passes in a value called data. This variable is an array in the form of [[[x1,y1,z1,],...],[[v1,v2,v3],...]]

in my viewcallable I have

import json

jsdata = json.dumps(data)

I want to put it into a javascript script tag section of my template so:

<script>
data=${jsdata}
</script>

but i’m pretty sure that syntax is incorrect. How can I do this?

Edit: from this: http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/templates.html it seems that Genshi style replacements are the way to go, which I take to mean that what I have above is correct. I am still unsure however, about whether this should be treated differently because it is going inside a javascript tag. Is this true?

  • 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-18T15:26:31+00:00Added an answer on June 18, 2026 at 3:26 pm

    You want to insert a JavaScript array, not a Python list.

    The easiest way to convert between Python and JavaScript formats is to use the json module. JSON is a JavaScript subset for data after all:

    import json
    
    jsdata = (json.dumps(data)
                .replace(u'<', u'\\u003c')
                .replace(u'>', u'\\u003e')
                .replace(u'&', u'\\u0026')
                .replace(u"'", u'\\u0027'))
    

    then pass jsdata to your template instead. The str.replace() calls ensure that the data remains HTML safe.

    In the template, interpolate this without escaping:

    <script>
    var data = ${structure:jsdata};
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a website using pyramid, and I want to fetch some data from
Building our Android app from Ant fails with this error: [apply] [apply] UNEXPECTED TOP-LEVEL
I'm building an app on Pyramid framework and would like to use the web2py-DAL
I'm building my first Pyramid app (coming from Pylons) and I'm trying to figure
Building a Django app on a VPS. I am not very experienced with setting
I'm building a web application in Pyramid and it needs user logins. Database backend
Building an app that gets a list of widgets from an SQlite database then
Building on this answer: https://stackoverflow.com/a/2349824/1382306 Are there further guidelines in A and B's usages,
Building an iOS app that needs to display some HTML string in a UIWebView
Building on the query in this answer (please note/assume that the GROUP_CONCAT s are

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.