Print to the console in Django without unicodeencodeerrors

Source: Internet
Author: User

When the environment under the line, normal operation, and then when the online environment, the addition of Chinese characters reported the following bug:

1 Traceback (most recent):   2 " views.py "  in <module>3     print  kwargs4'ASCII  ' codec can't encode character u'\xa0' in position 20:ordinal not in range (+)

The guess is that the online environment has gone through a uwsgi, and then went to search Uwsgi Django Unicodeencodeerror

Get a similar answer:

http://stackoverflow.com/questions/24887929/locale-on-django-and-uwsgi-Unicodeencodeerror
Http://chase-seibert.github.io/blog/2014/01/12/python-unicode-console-output.html

Two solutions were found after reading two articles:

1. Add the following configuration in the Uwsgi file

env = Pythonioencoding=utf-8

2. In the Django settings.py file, add

Import SYS Import  = codecs.getwriter ('UTF8'= codecs.getwriter ('UTF8 ') (Sys.stderr)

Both of these scenarios have been tried to solve the bug.

Summary: Your TERMIANL can typically handle UTF8 characters just fine. The issue is actually this Python is just getting confused on what encoding the terminal accepts.

Print to the console in Django without unicodeencodeerrors

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.