Jossie Calderon
Jossie Calderon

Reputation: 1415

The empty path didn't match any of these (django)

A similar question was asked here in The empty path didn't match any of these. The solution did indeed work when I included the path('',include('projects.urls')) within personal_portfolio.py. But here's what bugs ME...

personal_portfolio/urls.py:

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

projects/urls.py:

urlpatterns = [
path("", views.project_index, name="project_index"),
path("<int:pk>", views.project_detail, name="project_detail"),
]

The empty path IS contained (in the latter)! when the path('projects/', include('projects.urls')) is called, it should call projects/urls.py.

Then the empty path is there. Why do I need to include path("",include('projects.urls')) in personal_portfolio/urls.py for it to work?!

Upvotes: 0

Views: 958

Answers (2)

Alasdair
Alasdair

Reputation: 309109

path("", ...) is included by path('projects/', include('projects.urls')), therefore the path is:

'projects/' + "" = "projects/"

Therefore you need to access localhost:8000/projects/ and a request to localhost:8000/ will fail.

If you use path("", include('projects.urls')) instead, then the path is:

 "" + "" = ""

Now a request to the empty path localhost:8000/ will succeed.

Upvotes: 1

Jossie Calderon
Jossie Calderon

Reputation: 1415

You are using localhost:8000 instead of localhost:8000/projects to access your project.

If you do not have the empty path within your URL, the request will fail.

Upvotes: 0

Related Questions