[Fixed]-Getting 415 code with django.test.Client's patch method

27👍

As far as I know, httpie sends a request with the content-type application/json.

So, try this:

import json 
data = json.dumps({'text': 'new text'})

client.patch('/post/1/', data, content_type='application/json')
👤Linch

0👍

As for why you need to add a content_type for PATCH (and PUT, OPTIONS, DELETE). It’s because Django uses different defaults for content_type. For post it uses multipart/form-data while for the others it uses application/octet-stream. Not 100% sure why, but that explains the POST/GET succeeding

Leave a comment