无法导入“rest_framework”pylint(导入错误)

Unable to import 'rest_framework'pylint(import-error)

无法导入 rest 框架

from rest_framework import serializers
from EmployeeApp.models import Department, Employees

class DepartmentSerializer(serializers.ModelSerializer):
    class Meta:
        model = Department
        fields = ('DepartmentId',
                  'DepartmentName')

class EmployeeSerializer(serializers.ModelSerializer):
    class Meta:
        model = Employees
        fields = ('EmployeesId',
                  'EmployeeName',
                  'Department',
                  'DateOfJoining',
                  'PhotoFileName')
                  

您是否安装了 django-rest-framework 然后将其添加到 settings.py

中已安装的应用程序中

首先使用

安装它
pip install django-rest-framework

然后将其添加到 settings.py

中已安装的应用程序
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework', 
]