4
The problem here is that the APIClient
is sending data to the view as form-data by default, which doesn’t have a concept of None
or null
, so it is converted to the unicode string None
.
The good news is that Django REST framework will coerce a blank string to None
for relational fields for this very reason. Alternatively, you can use JSON and actually send None
or null
, which should work without issues.
5
In addition to what Kevin already said, you can force the APIClient to send JSON using the parameter format='json'
.
See the documentation.
- [Django]-Use django-import-export with class based views
- [Django]-Ngnix – duplicate upstream "app_server" in /etc/nginx/sites-enabled/django
4
In addition to existing answers,
if you are expecting a null, this probably means you expect your api to receive json.
If that’s the case, you may want to configure the test request default format to json instead of form-data:
In your setting.py:
REST_FRAMEWORK = {
...
'TEST_REQUEST_DEFAULT_FORMAT': 'json'
}
This way, no need to add format='json'
to each request
- [Django]-Refactor this Python code to iterate over a container
- [Django]-Admin site uses default database in Django 1.6