0

I am trying to send POST to my database through POSTMAN and I get 404 not Found status. Here is my views and urls.

#views
`class PlantViewSet(ModelViewSet):
    queryset = Plant.objects.all()
    serializer_class = PlantSerializer
    parser_classes = (MultiPartParser, FormParser)

    def create(self, request, *args, **kwargs):
        text = request.data["text"]
        price = request.data["price"]
        picture = request.data["picture"]

        Plant.objects.create(text=text, price=price, picture=picture)
        return Response("Plant created successfully", status=status.HTTP_200_OK)
`
#App.urls
`router = DefaultRouter()
router.register('plants/', views.PlantViewSet)
urlpatterns = [
    path('api/', include(router.urls))
]`

#project.urls
`
urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('App.urls'))
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)`

I tried Google, ChatGPT, Youtube and none of them helped. Please help!

2 Answers 2

0

Going through what You have mentioned here, what you can do is check for all the urls that has been defined on your project, you can do so using the 'django_extensions' and following a simple command i.e. 'python manage.py show_urls'. Check this thread our if you need help, How can I list urlpatterns (endpoints) on Django?

Sign up to request clarification or add additional context in comments.

Comments

0

Try using router.register("plants", PlantViewSet). Notice there's no / slash at the end. If you add an extra / at the end of url, it'll generate routes like this

/api/u//{username}/

Swagger Screenshot

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.