94๐
โ
You need to specify header as 'HTTP_X_HTTP_METHOD_OVERRIDE'
instead of 'X_HTTP_METHOD_OVERRIDE'
i.e. add HTTP_
at the beginning of the header.
header = {'HTTP_X_HTTP_METHOD_OVERRIDE': 'PUT'}
response = client.post('/model/1/', content_type='application/json', data=post_data_clean, **header)
From the Django documentation:
HTTP headers in the request are converted to
META
keys by converting
all characters to uppercase, replacing any hyphens with underscores
and adding anHTTP_
prefix to the name. So, for example, a header
calledX-Bender
would be mapped to theMETA
keyHTTP_X_BENDER
.
๐คRahul Gupta
11๐
Also, you can pass headers to the constructor of the Client:
from django.test import Client
client = Client(HTTP_USER_AGENT="Mozilla/5.0 ...", HTTP_X_USER_ID="982734")
This way every request will contain default headers.
PS: This approach is valid for DRF TestApiClient and ApiRequestFactory.
๐คusername
- [Django]-Error: Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>
- [Django]-Django Static files 404
- [Django]-How to write setup.py to include a Git repository as a dependency
Source:stackexchange.com