在Heroku上,locale.getdefaultlocale()返回(None,None),打破Django createsuperuser - 如何修复?

goj*_*omo 4 python django heroku

试图做一个heroku python manage.py createsuperuser给我一个大致结束的错误:

File "/usr/local/www/site-python/lib/django-trunk/django/contrib/auth/management/__init__.py", line 85, in get_system_username
 return getpass.getuser().decode(locale.getdefaultlocale()[1])
TypeError: decode() argument 1 must be string, not None
Run Code Online (Sandbox Code Playgroud)

输入shell确认:locale.getdefaultlocale()在我的Heroku Cedar堆栈上返回(None,None).如何设置区域设置以便python选择它?

goj*_*omo 17

回答我自己的问题:事实证明,这可以通过设置一个heroku配置变量来修复,这会导致python可以获取的环境变量,它返回locale.getdefaultlocale()中的可用值.

在我的情况下,我使用的heroku设置是:

heroku config:add LANG=en_US.UTF-8
Run Code Online (Sandbox Code Playgroud)

(当然,其他编码,特别是语言值可能对其他人有意义.)

它修复了createsuperuser问题,到目前为止一切都很好.(其他报告建议用户执行syncdb并选择创建超级用户,然后在某些系统上也会遇到同样的错误.)

请注意,任何此类更改都会触发您的实例重新启动.