Search code examples
pythondjango-rest-frameworkpylintdjango-serializer

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


Unable to import rest frame work

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')
                  

Solution

  • Did you install django-rest-framework and then add it to installed apps in settings.py

    First install it using

    pip install django-rest-framework
    

    Then add it to installed apps in settings.py

    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'rest_framework', 
    ]