views:

33

answers:

1

Django when i send the following string from an ajax submit i get the following string in unicode.How to decode this

    $.post("/records/save_t/",snddata,
     function(data){
     if(data == 0 ){
     }
      },"json");

In django

def save_t(request):
    if request.method == 'GET':
        qd = request.GET
    elif request.method == 'POST':
        qd = request.POST
    map_str = qd.getlist('map_str')
    logging.debug(map_str)

Output is [u'##1##@1//##2##@1//']. How can I convert this to a string? str(map_str) did not work.

Also how to get the values in the pattern

 str = map_str.split("//")
 for s in map_str.split("//"):
     ...
     ...  
A: 

Why do you think you need to convert it to a string? What's wrong with it as Unicode? It should be perfectly usable as it is.

In any case, what you have is a list containing a single unicode string (because you've used getlist, which always unsurprisingly returns a list). Is the actual problem just that you want to get the actual data out of the list? Then use map_str[0] (of course, map_str is a bad name, because it's not a string but a list).

Or, don't use getlist, but a simple get to get a string rather than a list.

Daniel Roseman