[英]Pylance Intellisense not working as expected with Django
I'm trying to understand how to configure Pylance to make it work correctly in my Django project.我试图了解如何配置 Pylance 以使其在我的 Django 项目中正常工作。
Below is one of many examples where Pylance is not able to find what I'm looking for.以下是 Pylance 无法找到我要查找的内容的众多示例之一。 Here, I obviously need models
from django.db
.在这里,我显然需要来自django.db
的models
。 But there are only theses 6 suggestions below...但是下面只有这6条建议......
Here is what I know or tried:这是我所知道或尝试过的:
"python.analysis.extraPaths": ["${workspaceFolder}/dj_proj/dj_apps"]
-> which works to prevent missing imports.在我的 VS 代码配置中(使用 devcontainer.json ): "python.analysis.extraPaths": ["${workspaceFolder}/dj_proj/dj_apps"]
-> 用于防止丢失导入。 I have no false warnings about missing imports, just the inability to see the right suggestions in intellisense.我没有关于丢失导入的错误警告,只是无法在智能感知中看到正确的建议。__pycache__
and .pyc
files -> no effect我清理__pycache__
和.pyc
文件 -> 没有效果__init__.py
pretty much everywhere我确保到处都有一个__init__.py
sys.path
(PYTHONPATH) looks like this (where dj_proj
is my django project and dj_apps
my apps folder):我的sys.path
(PYTHONPATH) 看起来像这样(其中dj_proj
是我的 django 项目和dj_apps
我的应用程序文件夹):['/workspace/dj_proj/dj_apps',
'/workspace/dj_proj',
'/usr/local/lib/python310.zip',
'/usr/local/lib/python3.10',
'/usr/local/lib/python3.10/lib-dynload',
'',
'/usr/local/lib/python3.10/site-packages']
I'm suspecting this PYTHONPATH variable to be messy or not sorted the right way, but I'm not sure.我怀疑这个 PYTHONPATH 变量是混乱的或者没有以正确的方式排序,但我不确定。
Any idea on what could be wrong?关于可能出什么问题的任何想法? Thanks!谢谢!
I believe you should install the Django extension in VS Code.我相信您应该在 VS Code 中安装 Django 扩展。 Even though some obvious stuff gets always overseen by the language support, at least that extension contains some useful stuff like pre-made models, CBVs and widely-used imports such as these:尽管语言支持总是会监督一些明显的东西,但至少该扩展包含一些有用的东西,如预制模型、CBV 和广泛使用的导入,例如:
I hope this is useful to you.我希望这对你有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.