One of the reason for this issue is if you have a middleware added into django middleware list in settings.py but haven't installed it yet.
In my case I added corsheaders.middleware.CorsMiddleware which wasn't installed.I installed it using pip install django-cors-headers and that did the trick.