2016-07-08 45 views
1

請,我是django的新用戶,我不明白我的模型中有什麼問題。 我已經激活了管理,並創建了一個新的模式:django管理編碼錯誤添加新項目時

class Strumenti(models.Model): 
    cod_stru = models.AutoField(db_column='cod_stru', primary_key=True) 
    sht_name = models.CharField(db_column='sht_name', max_length=15, blank=True, null=True) 
    descr = models.CharField(db_column='descr', max_length=45, blank=True, null=True) 
    isin = models.CharField(db_column='isin', max_length=16) 
    tipo = models.CharField(db_column='tipo', max_length=1) 
    mktcode = models.ForeignKey(Mercati, on_delete=models.CASCADE, default=1) 
    ccy1 = models.ForeignKey(Valute, related_name='ccyone', on_delete=models.CASCADE) 
    ccy2 = models.ForeignKey(Valute, related_name='ccytwo', on_delete=models.CASCADE) 
    beta = models.DecimalField(db_column='beta', max_digits=2, decimal_places=2, blank=True, null=True) 
    system = models.NullBooleanField(db_column='system', default=False, null=True) 
    template = models.NullBooleanField(db_column='template', default=False, null=True) 
    tenor = models.CharField(db_column='tenor', max_length=4, blank=True, null=True) 
    divy = models.DecimalField(db_column='divy', max_digits=5, decimal_places=5, blank=True, null=True) 
    fxpair = models.CharField(db_column='fxpair', max_length=6, blank=True, null=True) 
    cod_emitt = models.ForeignKey(Emittenti, on_delete=models.CASCADE, null=True) 
    idx_code = models.ForeignKey(Indexdef, on_delete=models.CASCADE, null=True) 
    vol_type = models.IntegerField(db_column='vol_type', blank=True, null=True) 

def __unicode__(self): 
     return u'%s - %s - %s - %s' % (self.cod_stru, self.sht_name, self.descr, self.tipo) 

,當我嘗試添加一個新的記錄,我得到這個錯誤:

**'ascii' codec can't encode character u'\xe3' in position 14: ordinal not in range(128)** 

我使用Django 1.9,Python 2.7版中,MySQL (utf8_unicode_ci)

下面的錯誤模板中渲染

In template /usr/local/lib/python2.7/dist-packages/django/contrib/admin/templates/admin/change_form.html, error at line 33 
ascii 
23 {% endblock %} 
24 {% endif %} 
25 
26 {% block content %}<div id="content-main"> 
27 {% block object-tools %} 
28 {% if change %}{% if not is_popup %} 
29 <ul class="object-tools"> 
30  {% block object-tools-items %} 
31  <li> 
32   {% url opts|admin_urlname:'history' original.pk|admin_urlquote as history_url %} 
33   <a href="{% add_preserved_filters history_url %}" class="historylink">{% trans "History" %}</a> 

有人可以幫我嗎?

回答

0

好的,我發現了這個問題。 我在'Valute'表中存儲了「聖多美和普林西比」的描述。

chars likeãéí產生錯誤,即使我不明白爲什麼我的.encode(uft-8)沒有工作... 任何爲什麼我只是將字符串更改爲「聖多美和普林西比「,現在看起來很好。