Issue
I keep running into an error trying to execute the Django Writing your first Django app tutorial. I am running Windows 10, Python 3.9.6, Django 3.2.9, and Vscode 1.63.0.
I'm on the step where I create a URLconf file called urls.py in the polls directory. The polls directory is at the same level as the manage.py script and the mysite folder (see folder structure screenshot below). Prior to this, I copy/pasted the code in the views.py, which runs fine. However, the tutorial then says to copy/paste code into the newly-created urls.py, which is again is in the polls directory. The code is:
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
The "from django.urls import path" line runs fine, but the "from . import views" line gives me the following error:
ImportError: attempted relative import with no known parent package
I have watched YouTube tutorials on relative imports and viewed the related stack overflow pages but no amount of tinkering with the code has yielded results. Does anyone know what I'm possibly doing wrong? I feel like since both views.py and urls.py should be able to reference each other, since are in the same folder (polls, which again sits at the same level as manage.py). I haven't been able to figure this out for a while, so any advice would be appreciated. Thank you!
Solution
Change
from . import views
to
from polls import views
Answered By - Sumithran
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.