0

I have a python list: categoriesPython, which is ['Firefox 2.0', 'Firefox 3.0', 'Firefox 3.5', 'Firefox 3.6', 'Firefox 4.0'], I did(I am using web.py):

data: {
       name: 'Firefox versions',
       categories: $categoriesPython,
       version: [0.20, 0.83, 1.58, 13.12, 5.43]
      }

I expected to get:

data: {
       name: 'Firefox versions',
       categories: ['Firefox 2.0', 'Firefox 3.0', 'Firefox 3.5', 'Firefox 3.6', 'Firefox 4.0'],
       version: [0.20, 0.83, 1.58, 13.12, 5.43]
      }

However, I got:

data: {
       name: 'Firefox versions',
       categories: ['Firefox 2.0', 'Firefox 3.0', 'Firefox 3.5', 'Firefox 3.6', 'Firefox 4.0'],
       version: [0.20, 0.83, 1.58, 13.12, 5.43]
      }

1. Because data is Json format, there cannot be have any assign value, for example:

    data: {
       name: 'Firefox versions',
       categorieData.push('$categoriesPython');
       categories: categorieData,
       version: [0.20, 0.83, 1.58, 13.12, 5.43]
      }

also, I do not want to convert python list to javascript list, because the list have more than 200 value, if convert, there must be have more than 200 categorieData.push('$categoriesPython');, the code will be redundant.

How can I get the expected result?

1 Answers1

0

From the docs on Filtering it would appear that

$:categoriesPython

might do the trick

By default, Templetor uses web.websafe filter to do HTML-encoding.

render.hello("1 < 2") "Hello 1 < 2"

To turnoff filter use : after $. For example:

The following will not be html escaped. $:form.render()

sberry
  • 128,281
  • 18
  • 138
  • 165
  • It works, but I got: [u'Firefox 2.0', u'Firefox 3.0', u'Firefox 3.5', u'Firefox 3.6', u'Firefox 4.0'], how can I remove u prefix? – user2465557 Jun 08 '13 at 05:34
  • Yes, I fixed:http://stackoverflow.com/questions/1207457/convert-unicode-to-string-in-python-containing-extra-symbols – user2465557 Jun 08 '13 at 05:41
  • BTW, you don't need to do what is in that answer to convert (your examples) to none-Unicode strings. Just do `str(item)` where item is your current Unicode string. – sberry Jun 08 '13 at 05:47
  • I did $str(item) in the html part, but I got "global name 'str' is not defined"... – user2465557 Jun 09 '13 at 03:56