问题
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.'.
This is my urls.py file.
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()),
]
This is the settings.json file found when I use the Configure Language Specific Settings... option.
{
"C_Cpp.updateChannel": "Insiders",
"[python]": {
}
}
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.
回答1:
I had the same problem with wrong unresolved import errors in vscode. I suggest that you see the answers to this question as one of the answers might solve your problem as well.
回答2:
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"],
Remember to inlude your Project folder along the path to your actual code file

来源:https://stackoverflow.com/questions/61412408/unresolved-import-in-my-django-project-vscode