Hello Django devs!

I'm a long time Django user and nowadays work with sites where Django is 
mostly or only an API for the front end. I'm assuming this is not an exotic 
use case in 2022.

One pain point I continue to come across over and over again is that Django 
by default only speaks text/html even if the request has application/json 
accept headers. This often results in situatios where the unassuming JS app 
burps a HUGE html response as a string to the user when something goes 
wrong. And yes, it's obviously not Djangos fault if the frontend developer 
is sloppy but I believe there's lots of things we could improve here.

Some spesific things we could improve:
- At least for 400, 500, and CSRF errors, send JSON (or empty response) 
back instead of HTML if the request is xhr or has JSON headers
- Make it easy to override the JSON like we can do with HTML
- Add good documentation to explain how this works and how it can be 
customized

I'm interested in hearing comments about this, and opinions from the core 
devs if this would be something that could be built into Django. I haven't 
been active here for a looong time but this is a bit of a pet peeve of mine 
and I would be more than happy to implement this also.

And to be clear, I understand we already have middleware APIs and various 
settings to handle this but my point is that I think handling this in 
Django core (even as an optional setting or middleware) would be most 
useful and right way to do this for the community.

Sorry for the long post.

Cheers,

- VS

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/68ced6ec-342f-42f6-ba0b-1a51360fa119n%40googlegroups.com.
  • For... Ville Säävuori
    • ... Jacob Rief
    • ... Tobias Bengfort
      • ... vanadium23
        • ... 'Adam Johnson' via Django developers (Contributions to Django itself)

Reply via email to