title: What's the different between "# -*- coding: utf-8 -*-" ，"from __future__ import unicode_literals" and "sys.setdefaultencoding("utf8")"
body: <p><strong>What I know is:</strong></p>
  
  <ol>
  <li><p><code># -*- coding: utf-8 -*-</code><br>
  It is used to declare the encoding of a Python source file, once I set the encoding name, Python parser will interpret the file using the given encoding. I call it "<strong>file encoding</strong>";</p></li>
  <li><p><code>from __future__ import unicode_literals</code> 
  I'm doing my tasks using Python2.7, and I use <code>from __future__ import unicode_literals</code> to change the default type of string from "str" to "unicode". I call it "<strong>string encoding</strong>";</p></li>
  <li><p><code>sys.setdefaultencoding('utf8')</code>
  But sometimes, I get an error in Django, for example, I stored Chinese in admin, then I visited the releated pages</p>
  
  <blockquote>
    <p>UnicodeEncodeError at /admin/blog/vulpaper/29/change/<br>
    'ascii' codec can't encode characters in position 6-13: ordinal not in range(128)<br>
    ....the more error information<br>
    The string that could not be encoded/decoded was: emcms外贸网站管理系统 </p>
  </blockquote>
  
  <p>for this problem, I will write <code>sys.setdefaultencoding('utf8')</code> in Django settings file to solve it. </p></li>
  </ol>
  
  <p><em>But Actually, I don't know the tech detail of the above.</em></p>
  
  <p><strong>What make me confused is:</strong><br>
  1. Since I set the python source file encoding, why should I set the string encoding to ensure my string's encoding is my favorite encoding?<br>
  What's the different between "file encoding" and "string encoding"?<br>
  2. Since I set the "file encoding" and "string encoding", why do UnicodeEncodeError still happen?</p>