Salma Salma - 1 year ago 91
Javascript Question

send a list of string elements in Django

I am new to Django. This is my Tag model

class Tag(models.Model):

I send a list of all tags name to a template. I want to use it in a javascript code. The problem is that, the list looks like this in javascript

[u'c++', u'c#', u'php', u'python',

It should be as this

['c++', 'c#', 'php', 'python', 'django']

I think it's some thing about unicode, but I do not know how to handel it. any help please?

excuse my bad english

Answer Source

Can you tell me whether the mistake is when you render the first time the view, or is an ajax call?, I think you are doing ajax call, then can you debug the django process, and write here what are the datas that you recover of your database, please?.

In addition, can you put the json serializer that you are using please?

If you try the next code, you can see the problem is not unicode:

         import json
         json.dumps([unicode(i) for i in range(10)])

result: '["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]'

try send the above data, and tell us the result please. Thanks!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download