2017-07-31 2 views
1

J'utilise django, nginx et gunicorn.Django FileField ne fonctionne pas avec "Umlaut" allemand (ä, ö, ü)

Dans mes modèles j'ai un FileField qui ne fonctionne pas avec "Umlaute" allemand dans la production.

Lorsque je tente de télécharger un fichier (sélectionner le fichier et appuyez sur "Enregistrer") dans/admin avec un "Umlaut":

UnicodeEncodeError: 'ascii' codec can't encode character '\xe4' in position 27: ordinal not in range(128) 

models.py

class wiki(models.Model): 

    headline = models.CharField(max_length=255) 
    file = models.FileField(null=True, blank=True) 

    def __str__(self): 
     return self.headline 

Sur le Web de développement serveur sur la machine locale (./manage runserver) cela fonctionne très bien, donc j'ai pensé qu'il a quelque chose à voir avec gunicorn ou nginx et a fait les changements suivants sans succès:

/etc/systemd/system/gunicorn.se rvice:

(ajouté --env LANG = de_DE.UTF-8)

[Unit] 
Description=gunicorn daemon 
After=network.target 

[Service] 
User=django 
Group=www-data 
WorkingDirectory=/opt/django/project 
ExecStart=/opt/django/bin/python3 /opt/django/bin/gunicorn --env LANG=de_DE.UTF-8 --workers 3 --bind unix:/opt/django/gunicorn.sock uhd.wsgi:application 

[Install] 
WantedBy=multi-user.target 

/etc/nginx/sites disponibles/domaine

server { 
    charset UTF-8; 
} 

Voici quelques informations que je pense pourrait être utile:

$ locale

LANG=C.UTF-8 
LANGUAGE= 
LC_CTYPE="C.UTF-8" 
LC_NUMERIC="C.UTF-8" 
LC_TIME="C.UTF-8" 
LC_COLLATE="C.UTF-8" 
LC_MONETARY="C.UTF-8" 
LC_MESSAGES="C.UTF-8" 
LC_PAPER="C.UTF-8" 
LC_NAME="C.UTF-8" 
LC_ADDRESS="C.UTF-8" 
LC_TELEPHONE="C.UTF-8" 
LC_MEASUREMENT="C.UTF-8" 
LC_IDENTIFICATION="C.UTF-8" 
LC_ALL=C.UTF-8 

cat/etc/* - Libération

PRETTY_NAME="Debian GNU/Linux 8 (jessie)" 
NAME="Debian GNU/Linux" 
VERSION_ID="8" 
VERSION="8 (jessie)" 
ID=debian 
HOME_URL="http://www.debian.org/" 
SUPPORT_URL="http://www.debian.org/support" 
BUG_REPORT_URL="https://bugs.debian.org/" 

j'apprécie toute aide. Si plus d'informations sont nécessaires, s'il vous plaît faites le moi savoir.

+0

droite Python 2.x? 'def __str __ (self):' devrait être 'def __unicode __ (self):' – allcaps

+0

en fait c'est Python 3.5.3 en développement et Python 3.4.2 en production. –

+0

Je ne comprends jamais pourquoi les développeurs veulent utiliser deux Pythons différents pour prd et dev. Dans votre cas, il n'est pas susceptible d'être lié à votre problème. Mais c'est une mauvaise pratique. Il n'est pas difficile d'avoir plusieurs Pythons installés. Il n'est donc pas difficile de maintenir le développement et la production ** exactement ** pareils. – allcaps

Répondre

0

Je suis passé de Debian Jessie (oldstable) à Debian Stretch (stable) et maintenant tout fonctionne. Python a été mis à niveau de Python 3.4.2 vers Python 3.5.3. $ locale donne toujours la même sortie, gunicorn et nginx sont toujours les mêmes que ceux montrés dans la question.

$ cat/etc/* - libérer

PRETTY_NAME="Debian GNU/Linux 9 (stretch)" 
NAME="Debian GNU/Linux" 
VERSION_ID="9" 
VERSION="9 (stretch)" 
ID=debian 
HOME_URL="https://www.debian.org/" 
SUPPORT_URL="https://www.debian.org/support" 
BUG_REPORT_URL="https://bugs.debian.org/"