1

I am trying to run my first Django application and when I run server I get the following error:

ImportError: cannot import name 'urlpatterns' from 'django' (C:\Users\Chris\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\__init__.py)

Why is the following command that I use in views.py giving me errors:

from django import urlpatterns

As far as I know it should work? I have tried searching the web for an answer but I couldn't find anything.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
c2000
  • 11
  • 3

1 Answers1

1

There is no need to import urlpatterns from anywhere. urlpatterns is a variable that should be defined in the urls.py file, so:

from django.contrib import admin
from django.urls import include, path

# from django import urlpatterns

urlpatterns = [
    path('tasks/', include('tasks.urls')),
]

There also should not be a trailing comma after the closing square bracket (]).

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555