DRF-level middlewares ?

36 views
Skip to first unread message

Pascal Chambon

unread,
Aug 4, 2020, 5:19:51 AM8/4/20
to Django REST framework
Hello everyone, 

I've recently needed to force the active Django language depending on the user's profile, however since this oauth-token-based auth is done only at DRF-view level, I couldn't resolve it with a normal Django middleware.

It seems to be a recurring problem (ex. https://github.com/jpadilla/django-rest-framework-jwt/issues/45), when django middelware don't have enough access to DRF data, and DRF itself doesn't seem to provide application-global hooks to interact with requests (ex. to enforce some constraints or validation on query params, on current language, etc.).

I've seen solutions using mixins (but it requires edit access to all used views), or using filters (but it looks like hacks). And since several features (like user auth) sem to be lazy/on-demand, even a custom authentication backend wouldn't necessarily solve my own issue in all cases.

Have there already been discussions on some DRF-level hook system, similar to Django's MIDDELWARE setting ? Or am I missing something already in place ?  
(for now people are backporting DRF features like JWT or oauth to middelwares, but it makes duplicate DB calls, and duplicates app logic, so it's not entirely satisfying imo)

thanks in advance for your input !

regards,
Pascal
Reply all
Reply to author
Forward
0 new messages