How can I send headers in Django REST framework browsable API view, I am authenticating calls by matching a token and that is passed in headers. I can use that API in the postman and it's working great, but I want to give inputs for putting access token on the browsable API of Django REST framework.
For reference like where I want the inputs for headers, I'm attaching a picture of the UI.
Any help is appreciated. Thanks
Adding login to the Browsable API In order to do so we'd need to be able to login as a user. We can add a login view for use with the browsable API, by editing the URLconf in our project-level urls.py file. And, at the end of the file, add a pattern to include the login and logout views for the browsable API.
The browsable API feature in the Django REST framework generates HTML output for different resources. It facilitates interaction with RESTful web service through any web browser. To enable this feature, we should specify text/html for the Content-Type key in the request header.
You just need to put the field in your ModelSerializer and set content-type=multipart/form-data; in your client. BUT as you know you can not send files in json format. (when content-type is set to application/json in your client). Unless you use Base64 format.
Check modheader. It allows you to set headers for your request. You can set the token authtoken there where "Name" would be "Authorization" and "Value" would be "Token ".
In my case, I was using rest_framework_JWT so, Authorization headers were like "JWT your_token".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With