Home > Mobile >  Page not found 404 django
Page not found 404 django

Time:12-13

Can anyone help me with this please? When I try to access i get the following error:

Request Method: GET Request URL: http://127.0.0.1:8000/ Using the URLconf defined in backend.urls, Django tried these URL patterns, in this order: admin/ 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.

urls.py

from django.contrib import admin
from django.urls import path, include
from Notes.views import NotesViewset
from rest_framework.routers import DefaultRouter

router=DefaultRouter()
router.register('/posts',NotesViewset)

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

views.py

from django.shortcuts import render
from .models import Note
from rest_framework import viewsets
from .serializers import NoteSerializer


class NotesViewset(viewsets.ModelViewSet):
    serializer=NoteSerializer
    queryset=Note.objects.all()

admin.py

from django.contrib import admin

I'm new to programming and I hope someone can help me. Thanks

CodePudding user response:

You added " " space character of router.urls. Remove it;

from django.contrib import admin
from django.urls import path, include
from Notes.views import NotesViewset
from rest_framework.routers import DefaultRouter

router=DefaultRouter()
router.register('/posts',NotesViewset)

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include(router.urls)) # <-- removing the " " character 
]

Look at the official documentation;
https://docs.djangoproject.com/en/4.1/intro/tutorial01/#write-your-first-view

  • Related