Django character encoding error Solution

Source: Internet
Author: User

To learn limodou step by step, complete an address book based on the example in Chapter 7. OS: Debian etch locale: zh_CN.UTF-8 Django 1.0 python2.4.4 address/models. the py content is as follows # Coding = UTF-8 2 3 from Django. DB import models 4 5 # create your models here. 6 7 Class address (models. model): 8 name = models. charfield ('name', max_length = 20, unique = true) 9 Gender = models. charfield ('gender ', choices = ('M', 'male'), ('F', 'female'), 10 max_length = 1) 11 telephone = models. charfield ('telephony ', max_length = 20) 12 mobile = mod Els. charfield ('cell phone ', max_length = 11) 13 14 15 class admin: 16 pass on the admin page, you can add and save the address object. Click address object, the record content can be correctly displayed. Add def _ STR _ (Self): return self. the name of the address object is displayed in the admin interface, but the following error occurs when you click the name to display the content: templatesyntaxerror at/admin/address/1/caught an exception while rendering: 'ascii 'codec can't encode characters in position 0-2: ordinal not in range (128) original traceback (most recent call last): file "/usr/lib/python2.4/Site-packages/Django/template/debug. PY ", line 71, in render_node result = node. render (context) file "/usr/lib/python2.4/Site-packages/Django/template/debug. PY ", line 87, in render output = force_unicode (self. filter_expression.resolve (context) file "/usr/lib/python2.4/Site-packages/Django/template/_ init __. PY ", line 559, in resolve new_obj = func (OBJ, * arg_vals) file"/usr/lib/python2.4/Site-packages/Django/template/defaultfilters. PY ", line 31, in _ dec ARGs [0] = force_unicode (ARGs [0]) file"/usr/lib/python2.4/Site-packages/Django/utils/encoding. PY ", line 52, in force_unicode S = Unicode (STR (s), encoding, errors) unicodeencodeerror: 'ascii 'codec can't encode characters in position 0-2: ordinal not in range (128) solution: __str _ () changed to _ Unicode _ () After Django was upgraded to 1.0, there were some changes, the class admin is no longer used to generate management interfaces.

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.