【问题标题】:Django Internationlization in Python2 not working (Unicode Decode Error)Python2 中的 Django 国际化不起作用(Unicodedecodeerror)
【发布时间】:2023-03-08 01:38:02
【问题描述】:

我尝试在 Django 中实现 Internationalize 我在这里学习了本教程:https://medium.com/@nolanphillips/a-short-intro-to-translating-your-site-with-django-1-8-343ea839c89b

但是每当我执行“python manage.py makemessage -l en”命令时,我都会得到一个如下所示的 UnicodeDecodeError “UnicodeDecodeError:‘ascii’编解码器无法解码位置 1 的字节 0xe9:序数不在范围内 (128)”

我还尝试将 bashrc 和环境文件中的语言环境设置更改为:

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

但运气不好,错误仍然存​​在

有什么想法吗?谢谢

【问题讨论】:

  • 您的源代码是否包含 unicode 字词?尝试在页面顶部包含# -*- coding: <encoding name> -*-。更多check here
  • 请添加来自makemessages的完整回溯(输出)。

标签: django internationalization


【解决方案1】:

感谢您的宝贵时间。这是 makemessages 的输出:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/makemessages.py", line 326, in handle
    potfiles = self.build_potfiles()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/makemessages.py", line 356, in build_potfiles
    file_list = self.find_files(".")
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/makemessages.py", line 411, in find_files
    for dirpath, dirnames, filenames in os.walk(root, topdown=True, followlinks=self.symlinks):
  File "/usr/lib/python2.7/os.py", line 286, in walk
    if isdir(join(top, name)):
  File "/usr/lib/python2.7/posixpath.py", line 80, in join
    path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 1: ordinal not in range(128)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-05
    • 2014-02-15
    • 1970-01-01
    相关资源
    最近更新 更多