[Django]-Django return " 500 INTERNAL SERVER ERROR" when $.post a utf-8 string

2👍

You’re probably getting an UnicodeEncodeError because

request.POST.get('location')

returns an unicode object. When you try to print it, Python tries to encode it using the ‘ascii’ codec and fails because it contains non-ascii chars.

If you really want to print it, use:

print request.POST.get('location').encode('utf-8')

EDIT: more info about encodings in Python: https://docs.python.org/2/howto/unicode.html

0👍

Finally, I find a magic way to solve this problem . I just comment the print statement in view. But I’m still not sure for its reason.

Leave a comment