在我的Django项目中未解析的导入:VSCode [英] Unresolved import in my django project : VSCode

查看:40
本文介绍了在我的Django项目中未解析的导入:VSCode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 ubm-app 的Django项目,其中有两个应用程序 main ubm-app .我在 main 应用程序的 views.py 文件中创建了两个类,分别是 URLAdder URLModifier .我试图通过使用 from行将这些视图导入到我的 urls.py 文件中.导入视图,但是VS Code向我显示错误未解决的导入'c:\ Users \ Hari \ Desktop \ django \ UBM-App \ main'..

I have a Django project called ubm-app with two apps, main and ubm-app. I've created a couple of classes, URLAdder and URLModifier in the views.py file in the main app. Im trying to import these views into my urls.py file by using the line from . import views but VS Code shows me the error unresolved import 'c:\Users\Hari\Desktop\django\UBM-App\main.'.

这是我的 urls.py 文件.

from django.urls import path, include
from . import views

urlpatterns = [
    path('',views.home,name='home'),
    path('api/add/', views.URLAdder.as_view()),
    path('api/modify/',views.URLModifier.as_view()),
]

这是我使用 Configure Language Specific Settings ... 选项时找到的 settings.json 文件.

This is the settings.json file found when I use the Configure Language Specific Settings... option.

{
    "C_Cpp.updateChannel": "Insiders",
    "[python]": {



    }
}

这是我的Django项目的 .vscode 文件夹中的 settings.json 文件.

This is the settings.json file in the .vscode folder in my Django project.

{
    "python.pythonPath": "env\\Scripts\\python.exe"
}

任何人都可以通过解释建议解决此问题吗?我似乎一次又一次遇到这些未解决的导入错误.如果错误是基本错误,请原谅我.

Can anyone please suggest a fix to this with an explanation? I seem to be having these unresolved import errors time and again. Forgive me if the error is a basic one.

推荐答案

这是我的解决方案:在您的Vscode/setting.json上,只需将"Python.autoComplete.extraPaths"放置在对应于您的项目文件,以便在脚本上导入模块时,您的pyDev服务器可以检测到该模块,并且不会对您的代码显示任何错误.例如"python.autoComplete.extraPaths":["./您的脚本代码路径"],

This is my Solution: On your Vscode/setting.json simply place the "Python.autoComplete.extraPaths" to correspond to your Project File so that when you import a Module on your script, Your pyDev server can detect it and show no error to your Code. e.g "python.autoComplete.extraPaths": ["./path-to-your-script-code"],

请记住沿实际代码文件的路径包含您的Project文件夹

Remember to inlude your Project folder along the path to your actual code file

这篇关于在我的Django项目中未解析的导入:VSCode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆