导入“shortuuid.django_fields”无法解决

问题描述 投票:0回答:1

即使安装了 django-shortuuidfield 后,我也无法将 Shortuuid 或 Shortuuidfield 导入到我的 Python 代码中。我不知道怎么了

from django.db import models
from shortuuid.django_fields import ShortUUIDField 
from django.utils.html import mark_safe
from userauths.models import User


class category(models.Model):
    cid = ShortUUIDField(unique=True, length=10, max_length=20, prefix="cat", alphabet="abcdefgh12345")
    title = models.CharField(max_length=100)
    image = models.ImageField(upload_to='category')

我尝试更改“from”路径,例如(from .import ShortUUID)或其他实例,但我不断收到相同的错误

python django-models django-users
1个回答
0
投票
(env) C:\Users\Benedict\Documents\CODE\chiopeglobalservice>py manage.py makemigrations
Traceback (most recent call last):
  File "C:\Users\Benedict\Documents\CODE\chiopeglobalservice\manage.py", line 22, in <module>
    main()
  File "C:\Users\Benedict\Documents\CODE\chiopeglobalservice\manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\Benedict\Documents\CODE\chiopeglobalservice\env\Lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "C:\Users\Benedict\Documents\CODE\chiopeglobalservice\env\Lib\site-packages\django\core\management\__init__.py", line 416, in execute
    django.setup()
  File "C:\Users\Benedict\Documents\CODE\chiopeglobalservice\env\Lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\Benedict\Documents\CODE\chiopeglobalservice\env\Lib\site-packages\django\apps\registry.py", line 116, in populate
    app_config.import_models()
  File "C:\Users\Benedict\Documents\CODE\chiopeglobalservice\env\Lib\site-packages\django\apps\config.py", line 269, in import_models      
    self.models_module = import_module(models_module_name)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\importlib\__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1381, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1354, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1325, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 929, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 994, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "C:\Users\Benedict\Documents\CODE\chiopeglobalservice\core\models.py", line 40, in <module>
    class Category(models.Model):
  File "C:\Users\Benedict\Documents\CODE\chiopeglobalservice\core\models.py", line 41, in Category
    cid = ShortUUIDField(unique=True, max_length=20, prefix="cat", alphabet="abcdefgh12345")
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Benedict\Documents\CODE\chiopeglobalservice\env\Lib\site-packages\shortuuidfield\fields.py", line 25, in __init__
    super(ShortUUIDField, self).__init__(*args, **kwargs)
  File "C:\Users\Benedict\Documents\CODE\chiopeglobalservice\env\Lib\site-packages\django\db\models\fields\__init__.py", line 1200, in __init__
    super().__init__(*args, **kwargs)
TypeError: Field.__init__() got an unexpected keyword argument 'prefix'
© www.soinside.com 2019 - 2024. All rights reserved.