Zohaib Shamshad
Zohaib Shamshad

Reputation: 151

Include method under urls.py not working: Django

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

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.index, name='index'),
    path('dashboard/', include(pages.urls)),
]

I'm trying to use include method under my urls.py file to direct the dashboad/ request to my app urls.py file, which is not working.

As shown in image the when I'm trying to import views from pages it gives me error saying no module pages

Upvotes: 0

Views: 2281

Answers (2)

Swift
Swift

Reputation: 1711

Hi and welcome to StackOverflow!

The problem you are facing is that Django expects the include(...) method to be given a list of url patterns or the string of the module url's you want to be included at the path.

I would refactor your code like so:

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

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.index, name='index'),
    path('dashboard/', include('pages.urls')),
]

Upvotes: 1

ahmadgh74
ahmadgh74

Reputation: 821

change this line :

path('dashboard/', include(pages.urls)),

to this :

path('dashboard/', include('pages.urls')),

see this link

Upvotes: 4

Related Questions