I'm having difficulty understanding "include()" function in "urls.py"

Can anyone explain the include() function in “urls.py”?
Like in this code snippet

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

urlpatterns = [
    path('admin/', admin.site.urls),
    path("polls/", include("polls.urls"))
]

I mean if we here mean the “urls.py” file under the “polls” app, why don’t we use “polls/urls.py”?

This is an issue of Python syntax, not specific to Django. See the docs at django.urls functions for use in URLconfs | Django documentation | Django.

Notice how your import statements are written - you write from django.contrib import admin, not from django/contrib import admin.py.

See 6. Modules — Python 3.11.1 documentation and 5. The import system — Python 3.11.1 documentation for more detailed information.

1 Like

Thank you so much, sir! you are the saviour.