getting import could not be resolved on rest_framework.decorators

I have the following imports

from rest_framework.decorators import api_view
from rest_framework.response import Response

Import “rest_framework.decorators” could not be resolvedPylance[reportMissingImports] for both.

View Problem

Quick Fix… (Ctrl+.)

I am running venv and have installed djangorestframework

I have added “rest_framework” to to my settings.py INSTALLED_APPS

What am I missing?

Please post the full text of the error message you are receiving.

Import “rest_framework.decorators” could not be resolvedPylance[reportMissingImports] for both.

So this is a message you’re receiving in your IDE and not as a result of running runserver?

Yes it is in VSCode as I am writing the function based view from the example in the documentation.

Ok, so that’s a configuration issue with your project in VSCode. It’s not an actual problem in your application. You can fix it if you wish, but it’s not going to prevent you from working on your project.
(And no, I don’t know how to fix it. It’s never bothered me enough to worry about it. However, it’s most likely related to the “Interpreter” configured for your project. You should be using the instance of Python that’s in your venv.)

1 Like

ok yes other places where I import hose same packages I do not get that error. I will ignore unless I start getting run time errors.

I think this is a lil too late, but if you’re getting this issue, all you have to do is change your python interpreter to the environment you’re working in. You can do that by pressing Ctrl (or Command on mac) + Shift + P, and then navigating to “Python: Select Interpreter” and choosing the environment you’re correctly working in, should work perfectly fine then. Cheers!

if you have “Python (PyDev)” extension installed , try to uninstall
Just keep the one by Microsoft for python debugger