我正在尝试使用PostGreSQL数据库在服务器上部署Django应用程序(2.1.5和Python 3.6.6)。 我像往常一样执行了“ makemigrations”和“ migrate”,然后无法使用命令“ createsuperuser”创建超级用户:
[alex@web574 myproject]$ python3.6 manage.py createsuperuser
Nom d'utilisateur (leave blank to use 'alex'):
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/alex/webapps/global_hse_project/lib/python3.6/Django-2.1.5-py3.6.egg/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/alex/webapps/global_hse_project/lib/python3.6/Django-2.1.5-py3.6.egg/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/alex/webapps/global_hse_project/lib/python3.6/Django-2.1.5-py3.6.egg/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/alex/webapps/global_hse_project/lib/python3.6/Django-2.1.5-py3.6.egg/django/contrib/auth/management/commands/createsuperuser.py", line 60, in execute
return super().execute(*args, **options)
File "/home/alex/webapps/global_hse_project/lib/python3.6/Django-2.1.5-py3.6.egg/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/home/alex/webapps/global_hse_project/lib/python3.6/Django-2.1.5-py3.6.egg/django/contrib/auth/management/commands/createsuperuser.py", line 139, in handle
input_value = self.get_input_data(field, message)
File "/home/alex/webapps/global_hse_project/lib/python3.6/Django-2.1.5-py3.6.egg/django/contrib/auth/management/commands/createsuperuser.py", line 194, in get_input_data
raw_value = input(message)
UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 8: ordinal not in range(128)
我在Google上发现要添加:
# -*- Coding: utf-8 -*-
位于文件顶部,但不起作用,结果与变量DEFAULT_CHARSET(https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-DEFAULT_CHARSET)相同。 我的PostGreSQL数据库要求utf-8编码。
答案 0 :(得分:2)
这可能是由于标准输入法所使用的编码不支持在input()
提示符下键入的字符引起的。
在运行UTF-8
命令之前,您可以尝试使用PYTHONIOENCODING
环境变量将编码明确设置为createsuperuser
:
export PYTHONIOENCODING="UTF-8"; python3.6 manage.py createsuperuser
答案 1 :(得分:0)