If you are looking for a way to get a plain text error page when using curl
, you
need to add the HTTP header X-Requested-With
with value XMLHttpRequest
, e.g.
curl -H 'X-Requested-With: XMLHttpRequest' http://example.com/some/url/
Explanation: this is because Django uses the is_ajax
method to determine whether or not to return as plain text or as HTML. is_ajax
in turn looks at X-Requested-With
.
Update
Since django version 3.1, error reporting ignores the X-Requested-With
header. Instead, set the Accept
header on the request to any valid value which does not include the text/html
mime type.
e.g.
curl -H 'Accept: application/json;charset=utf-8' http://example.comp/some/url
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…