Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send headers in Django rest framework browsable API

Tags:

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.

enter image description here

Any help is appreciated. Thanks

like image 648
Rohit Khatri Avatar asked Sep 26 '16 05:09

Rohit Khatri


People also ask

How do I add login to the browsable API provided by DRF?

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.

What is 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.

How do I send a Django REST Framework?

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.


1 Answers

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".

like image 73
Adil Malik Avatar answered Sep 18 '22 02:09

Adil Malik