由于缺少 Microsoft.PythonTools.Django.Targets 文件,无法加载 Visual Studio 项目

Can't load Visual Studio project due to missing Microsoft.PythonTools.Django.Targets file

我已经从 GitHub 存储库中克隆了我的项目,并且在 Visual Studio 中打开项目时收到以下错误:

C:\path\to\project\test.pyproj : error : The imported project "C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Microsoft\VisualStudio\v16.0\Python Tools\Microsoft.PythonTools.Django.targets" was not found. Also, tried to find "Microsoft\VisualStudio\v16.0\Python Tools\Microsoft.PythonTools.Django.targets" in the fallback search path(s) for $(MSBuildExtensionsPath32) - "C:\Program Files (x86)\MSBuild" . These search paths are defined in "C:\Users\me\AppData\Local\Microsoft\VisualStudio.0_e9ead341\devenv.exe.config". Confirm that the path in the <Import> declaration is correct, and that the file exists on disk in one of the search paths. C:\path\to\project\test.pyproj

我已经尝试更改声明并尝试验证我是否安装了所有正确的 Visual Studio 工作负载,但问题仍然存在。该项目是一个 Web 应用程序 运行 Python,后端使用 Django,前端使用 JavaScript。

如果声明有问题或缺少必要的 Visual Studio 组件,就会发生此问题。在这种情况下,只是缺少一个组件。更具体地说,虽然安装了 Python 开发工作负载,但没有安装可选的“Python 网络支持”组件。要安装它,请打开 Visual Studio 安装程序,select“修改”,打开“单个组件”选项卡,搜索“Python Web 支持”并开始安装。应该注意的是,这也可以作为“工作负载”选项卡中“Python 开发”的可选组件进行安装。