gpt4 book ai didi

python - Django - 导入错误: cannot import name simplejson

转载 作者:太空宇宙 更新时间:2023-11-03 16:36:11 24 4
gpt4 key购买 nike

我是 Django 的初学者,我遇到了 ImportError: Cannot import name simplejson 错误。 Here ,有人建议更新extdirect的providers.py以导入json而不是simplejson,但我在长时间的网上冲浪后不知道如何做到这一点,而且我不知道什么是extdirect?最终,我的目标是将ORM查询结果集转为json并传递给客户端。

这是代码:

from django.core import serializers

vendors_json = AgreementVendors.objects.select_related('agreement_unique').all()
return serializers.serialize('json', [x.agreement_unique for x in vendors_json])

型号:

  class AgreementUnique(models.Model):
agreement_number = models.CharField(max_length=45, blank=True, null=True)
sign_date = models.DateTimeField(default=timezone.now)
cities = models.ForeignKey('address.Cities', on_delete=models.CASCADE)
sale_point = models.ForeignKey('legal_entity.SalePoint', on_delete=models.CASCADE)
sale_point_representative = models.ForeignKey('employee.Employees', on_delete=models.CASCADE)
partner_base = models.ForeignKey('PartnershipBase', on_delete=models.CASCADE)
agreement_from = models.DateField()
agreement_to = models.DateField()
blacknwhite = models.NullBooleanField()
prolongable = models.NullBooleanField()

class Meta:
managed = False
db_table = 'agreement_unique'

def __unicode__(self):
try:
return smart_unicode(AgreementEmployees.objects.get(agreement_unique=self.id).person_unique)
except AgreementEmployees.DoesNotExist:
return smart_unicode(self.agreement_number)

class AgreementVendors(models.Model):
agreement_unique = models.ForeignKey(AgreementUnique, on_delete=models.CASCADE)
vendors = models.ForeignKey('vendor.Vendors', on_delete=models.CASCADE)
return_percentage = models.FloatField()
payment_method = models.ForeignKey('additional.PaymentMethod', on_delete=models.CASCADE)
vendor_representative = models.ForeignKey('person.PersonUnique', on_delete=models.CASCADE)
days_of_payment = models.IntegerField()

class Meta:
managed = False
db_table = 'agreement_vendors'

def __unicode__(self):
return smart_unicode(self.vendors)

以及回溯:

Traceback (most recent call last):
File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 148, in get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 146, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\edgar\Desktop\Project\djprj\vendor\views.py", line 153, in create_new_vendor_agreement
return serializers.serialize('json', [x.agreement_unique for x in vendors_json])
File "C:\Python27\lib\site-packages\django\core\serializers\__init__.py", line 128, in serialize
s = get_serializer(format)()
File "C:\Python27\lib\site-packages\django\core\serializers\__init__.py", line 51, in __call__
raise self.exception
ImportError: cannot import name simplejson

此外,奇怪的是,当我尝试通过 Ctrl+F 项目范围内搜索 simplejson 时,我找不到任何一个 simplejson 出现

最佳答案

检查是否

SERIALIZATION_MODULES

在你的settings.py里面。它可能会覆盖默认的 json 序列化器。

关于python - Django - 导入错误: cannot import name simplejson,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37181284/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com