Django加载drf-yasg2时报错 ‘rest_framework.serializers‘ has no attribute ‘NullBooleanField‘

方和豫
2023-12-01

drf-yasg2执行时遇到报错:
AttributeError: module 'rest_framework.serializers' has no attribute 'NullBooleanField'
drf-yasg官方回复:
serializers.NullBooleanField has been removed in the latest DRF 3.14


解决方法:
drf-yasg2
release 1.19.4 要求 
    python 3.6 - 3.9
    Django 2.2 - 3.1
    Django REST Framework 3.8 - 3.12

已经安装的 djangorestframework 3.14.0
修改为:pip install djangorestframework==3.12


已经安装的Django 3.2.7
修改为:pip install django==3.1

重启django 服务
报错:
ImportError: Could not import 'drf_yasg2.generators.OpenAPISchemaGenerator' for 
API setting 'DEFAULT_GENERATOR_CLASS'. ImportError: cannot import name 'soft_unicode' from 'markupsafe'

尝试:
1、pip show markupsafe ===》Version: 2.1.1
2、from  markupsafe import soft_unicode  ==

 类似资料: