How to send headers in Django rest framework browsable API
Asked Answered
T

3

25

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.

Tacheometer answered 26/9, 2016 at 5:22 Comment(6)
You probably would need to extend that view manually as it is not something that's supported out of the box.Pluperfect
@Pluperfect Do you have any reference how to do this?Tacheometer
all I could find django-rest-framework.org/topics/browsable-api/#customizingPluperfect
@Pluperfect Well, I couldn't find anything useful on this. because even If I hard code the header input fields, how the rest framework will pass those attributes as headers while making api call?Tacheometer
Have you figured out the way to do it now?Anglian
@TrungTínTrần no.Tacheometer
B
5

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

Bagley answered 17/5, 2017 at 1:23 Comment(0)
K
0

you can use tools like Postman or you can add authentication.SessionAuthentication to your authentication_classes

authentication_classes = [authentication.TokenAuthentication, authentication.SessionAuthentication]

so as long as you are logged in you can see the put patch and options request on the page. by this method, you are not sending any Token. use it for development purposes.

Kan answered 4/1, 2020 at 15:25 Comment(0)
E
-1
  • In you postman select Post method and in Headers of request write Authorization for key and Token bd8877272b3384341d063d1 for value. Use you token generated for each user.
  • Or you can also enter username and password instead of token in Headers in postman.
Etom answered 9/1, 2017 at 11:54 Comment(1)
I know how to do that in postman, but I want to use the UI of django rest framework, and need a way to set headers in the UI.Tacheometer

© 2022 - 2024 — McMap. All rights reserved.