django TypeError:translation()取得未预期的保留字参数'codeset'

hi3rlvi2  于 2022-11-18  发布在  Go
关注(0)|答案(1)|浏览(1031)

我正在youtube上学习Python教程,需要创建一个django网站,但是我无法启动,因为当我输入“python manage.py runserver”时,我得到了“TypeError:平移()得到了一个意外的关键字参数'codeset'"的消息。我已经运行了视频像20倍,看看我是否错过了什么,但没有,因为它只是django网站教程的开始。我也尝试键入python3而不是python和一些其他选项,我看到堆栈溢出,但是没有一个与我得到的错误信息真正相关。也许有人知道如何修复这个问题?
我试图通过输入“python www.example.com runserver”来启动一个开发服务器manage.py,它应该在127.0.0.1:8000或其他位置启动一个django web服务器,但是我却得到了标题中指定的错误消息
密码:

PS C:\Users\kaspa\PycharmProjects\PyShop> python manage.py runserver
Exception ignored in thread started by: <function check_errors.<locals>.wrapper at 0x00000145784C1F80>
Traceback (most recent call last):
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\autoreload.py", line 248, in raise_last_exception
    raise _exception[1]
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\__init__.py", line 337, in execute
    autoreload.check_errors(django.setup)()
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\apps\registry.py", line 112, in populate
    app_config.import_models()
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\apps\config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\contrib\auth\models.py", line 94, in <module>
    class Group(models.Model):
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\base.py", line 139, in __new__
    new_class.add_to_class(obj_name, obj)
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\base.py", line 304, in add_to_class
    value.contribute_to_class(cls, name)
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\fields\related.py", line 1583, in contribute_to_class
    self.remote_field.through = create_many_to_many_intermediary_model(self, cls)
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\fields\related.py", line 1051, in create_many_to_many_intermediary_model
    'verbose_name': _('%(from)s-%(to)s relationship') % {'from': from_, 'to': to},
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\functional.py", line 149, in __mod__
    return str(self) % rhs
           ^^^^^^^^^
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\functional.py", line 113, in __text_cast
    return func(*self.__args, **self.__kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\translation\__init__.py", line 75, in gettext
    return _trans.gettext(message)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\translation\trans_real.py", line 286, in gettext
    _default = _default or translation(settings.LANGUAGE_CODE)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\translation\trans_real.py", line 199, in translation
    _translations[language] = DjangoTranslation(language)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\translation\trans_real.py", line 90, in __init__
    self._init_translation_catalog()
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\translation\trans_real.py", line 131, in _init_translation_catalog
    translation = self._new_gnu_trans(localedir)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\translation\trans_real.py", line 119, in _new_gnu_trans
    return gettext_module.translation(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: translation() got an unexpected keyword argument 'codeset

'

k2arahey

k2arahey1#

我也一直在关注Mosh的Python课程,遇到了同样的问题,来到这里寻求答案,然后自己做了一些更多的研究。
我是一个完全的初学者,我可能错了,但是在教程中,Mosh让我们安装django 2.1而不是当前版本的django。错误“translation()got an unexpected keyword argument 'codeset'”基本上意味着python认为在gettext_module.translation(在django 2.1中使用/创建的代码中)后面不应该有一个名为'codeset'的参数。
结果,在python gettext文档中,“在版本3.11中的更改:codeset参数被删除。".所以django 2.1有一些代码是python 3.11无法识别的,这会弹出一个错误。
解决方法:
1-删除了我的python“PyShop”项目。
2-已关闭PyCharm。
3-创建了一个新的“PyShop”项目。
4-在终端中,键入“pip uninstall django”。
5-然后通过在终端中输入“pip install django”安装当前版本的django(而不是教程中所示的pip install django==2.1)。
6-通过在终端中输入“django-admin startproject pyshop .”创建了“pyshop”文件夹。
7-在终端中键入“python manage.py运行服务器”。
瞧!没有更多的错误了,因为当前版本的django不会创建当前版本的python无法识别的代码。
新的python和堆栈溢出,抱歉的一些东西,我可能写错了或什么:)

相关问题