-1

I declared the URL pattern correctly, but I get 'Page Not Found error' if I go to the 'localhost:8000/rest' URL. here is the code snippet -

from myspace import views
from rest_framework import routers
from rest_api import views as rest_api_views

router = routers.DefaultRouter()
router.register(r'post', rest_api_views.GetEntryViewSet)

urlpatterns = [
    path('admin/', admin.site.urls),
    path('rest/',include('rest_framework.urls', namespace='rest_framework')),
    path('', include('myspace.urls')),
]

2 Answers 2

1

I think you missed the '/' in url. Try localhost:8000/rest/

Also, I think you need to update the `rest/' path in the urlpatterns

#current
path('rest/',include('rest_framework.urls', namespace='rest_framework')),

#updated
path('rest/', router.urls)

this is because currently, you are pointing to rest_frameworks.urls instead of the actual URLs.

Additionally, you can instead create the urls.py file in the rest_api app and move the routers related to the rest app into that.

# rest_api/urls.py
from rest_framework import routers
from rest_api import views as rest_api_views

router = routers.DefaultRouter()
router.register(r'post', rest_api_views.GetEntryViewSet)

urlpatterns = router.urls

Now use this file in the urls.py of the project.

from myspace import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('rest/',include('rest_api.urls', namespace='rest_api')),
    path('', include('myspace.urls')),
]
Sign up to request clarification or add additional context in comments.

2 Comments

I added the '/' in the end ..but still there is the same error.
Oh yes. I have updated the answer for the resolution of this error
0

Please Make sure you have installed and configured it correctly or not.

make sure have you included the URL. from django.conf.urls import include

For your reference

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.