Nitin Dagar
Nitin Dagar

Reputation: 31

django 404 error when running a server on window 10 with python 3

I am getting an error in my django project.

The /api and /admin urls are working fine, its only the main page that throws this error:

Using the URLconf defined in backend.urls, Django tried these URL patterns, in this order:

api-auth/

admin/

api/

The empty path didn't match any of these.

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

My urls.py file is as follow

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

urlpatterns = [
    path('api-auth/', include('rest_framework.urls')),
    path('admin/', admin.site.urls),
    path('api/',include('movies.api.urls'))
]

Upvotes: 1

Views: 144

Answers (2)

Adil Shirinov
Adil Shirinov

Reputation: 135

You have to specify the regex for the empty request ( Homepage)

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

urlpatterns = [
    re_path(r'^', include('app_name.urls')),
    path('api-auth/', include('rest_framework.urls')),
    path('admin/', admin.site.urls),
    path('api/',include('movies.api.urls'))
]

Upvotes: 2

Ralf
Ralf

Reputation: 16515

You have not defined a URL for your start page.

  1. You need to define a view for your start page (maybe you already have one?), or use a default view like TemplateView or something similar.
  2. you need to add a new URL to your patterns for that start page view; probably similar to this:

    urlpatterns = [
        path('', views.start_page, name='start_page'),
    
        path('api-auth/', include('rest_framework.urls')),
        path('admin/', admin.site.urls),
        path('api/',include('movies.api.urls'))
    ]
    

Upvotes: 1

Related Questions