[Fixed]-Django HTTP 404 error when PUT or GET

1👍

✅

You can’t GET anything until there is a record in the database. It’s hard to say without seeing your urls.py definition as well, but I’m assuming you set up /api/SecMeRe/patient/ to be the list view of patients.

You would need to PUT at the detail view of patient, which would be the url /api/SecMeRe/patient/353/ where 353 is the new primary key of your new Patient record.

Similarly, you could then call GET on that URL: /api/SecMeRe/patient/353/

If you want to not care about choosing IDs then use POST instead of PUT, and you can hit the original url of /api/SecMeRe/patient/.

The reason PUT requires you to call out the ID every time is because it’s an idempotent resource. You could call PUT on the url 100 times, and it would have the same result, since you are specifying the ID for both creating it and updating it.

Leave a comment