Django and Visual Studio Code with vitualenv Support
Recently i’m attracted by vs code appearance, and i decided to try it upon my ongoing Django.
I must say it just astonished when i opened my project regard it’s developed by Microsoft :). VS code will prompt a message for suggesting you install some extensions, actually it’s plugin, given the file you are editing. it’s not hard for me to install support for linting on python, django templates and javascript files.
But it occurs a problem when you have set a virtualenv environment on project: vs code cannot find python libraries given my project organizing like this:
— — project_virualenv— — — — — — — — — Scripts— — — — — — — — — Lib— — django_project_dir— — — — — — — — — — django_project— — — — — — — — — — — — — — — — — settings.py— — — — — — — — — — django_app1— — — — — — — — — — django_app2— — — — — — — — — — .vscode
Obviously Visual studio code can’t find python execution file and it’s in this structure, this is annoying when you try to using “find definition” and autocompletion in django.
And it turned out this problem can be solved by adding 2 absolute file in settings.json to specify python execution and libraries respectively:
{ “python.pythonPath”: “/project_virtualenv/scripts/python”, // auto complete in virtual env “python.autoComplete.extraPaths”: [ “/project_virtualenv/Lib/site-packages” ]}
And after adding these lines to settings.json, the debug seems to smart enough to find Django settings.py without changing default launch.json.
But it’s just so slow when you launch debug on Django, the response takes long time even on local develop environment.
