django-commons / django-debug-toolbar

A configurable set of panels that display various debug information about the current request/response.
https://django-debug-toolbar.readthedocs.io
BSD 3-Clause "New" or "Revised" License
8.08k stars 1.05k forks source link

Using DDT with DRF Simple JWT #1968

Closed ranganath294 closed 3 months ago

ranganath294 commented 3 months ago

i am using drf for my apis with simple jwt authentication. And the views are tightly integrated with JWT. So i cannot change to session auth. Browsable API does not work with JWT authentication. Is there any way to use django debug toolbar ?

I particularly want to use the SQL ppanel, for the n+1 related problem. DDT shows the duplicated queries which i want to use.

tim-schilling commented 3 months ago

Those requests should appear in the history panel if you click the refresh button in the history panel. You would need to trigger them first by using your application, then go to the history panel.

ranganath294 commented 3 months ago

But as i said there is no ui at all for my apis, so i wont be able to access any panel of DDT. And I use @apiview decorator for my apis. So the context of response if application/json

tim-schilling commented 3 months ago

Do you have the admin application installed? You can browse to that. You just need one page to be rendered from the django app. If not, create a basic view and wrap it with the @staff_member_required decorator

ranganath294 commented 3 months ago

This solves my problem temporarily. Created a dummy view which renders empty HTML and from there i am able to get to history page Thanks @tim-schilling But please do consider supporting DRF with JWT configuration

tim-schilling commented 3 months ago

@ranganath294 how would you propose it work?

ranganath294 commented 3 months ago

@tim-schilling i guess in this case (where ui is not possible)......

Try to make a default url which has empty html page (for which there won't be authentication in development)....that gives the debug toolbar panel. I guess authentication for that page won't be possible because of jwt. Or for authentication we can consider something like...upon accessing a url, user needs to enter the token and once it is authorized, authorized users will be able to access the debug toolbar. In my scenario, i have created a dummy endpoint which return a empty html page and from there i am accessing the previous hit views in history panel. There is no authentication but the page is accessible only in development mode.

Without any ui, just give some decorators (in case of functional based views) such that by the end of the view i.e before returning the response, it prints in terminal or it provides the entire data regarding the specific end point or view in a separate fixed or configurable endpoint.

tim-schilling commented 3 months ago

Getting the toolbar's info into the terminal is a big lift, though I'm not opposed to it.

Regarding creating a dummy endpoint that returns an empty html page, I think that's the best route forward for you. Typically this is the admin part of your application.