Home > Back-end >  Django REST Framework missing imports with Docker
Django REST Framework missing imports with Docker

Time:11-14

So, recently I've started creating project using Docker for the first time so my knowledge is not very great.

When I'm creating venv using python3 -m venv venv, and installing Rest Framework, everything works fine and I'm not having any problems at all.

But in my project with Docker, I have no idea why but PyLance detects missing imports with Django and Django REST.

enter image description here

It is really annoying, also when I'm making imports from Django, it makes suggestions:

enter image description here

But it won't suggest anything when making imports from REST

enter image description here

Does anyone know how to fix this issue? I've tried:

  • Opening VSC in different directories
  • Rebuliding Docker image

Everything works fine, my requirements file contains REST Framework therefore it works fine. It is all about theese non-sense missing modules.

CodePudding user response:

Are you opening VSCode inside the container? I have the same problem when opening files locally because everything is installed inside the container. To resolve it get VSCode to connect to your container. Then open the folder where your app resides in the container. Takes a bit for VSCode to install PyLance. Then it will ask you if you want to reload the window. After that it's fine. Whole process takes half a minute to a minute.

Edit: obviously your container needs to be up when connecting. After you've finished your work quit VSCode before running docker compose down. Next time the flow is: docker compose up. Once everything is running open VSCode. It will connect to your container immediately and open the correct folder, install PyLance, reload window, and you're done. Don't restart or down your container with VSCode open. It will try to reconnect and fail, plus refuse to quit in my case. Quit VSCode before a restart or doing docker compose down. YMMV.

  • Related