26

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.

6
  • You probably would need to extend that view manually as it is not something that's supported out of the box. Commented Sep 27, 2016 at 5:25
  • @serg Do you have any reference how to do this? Commented Sep 27, 2016 at 5:47
  • all I could find django-rest-framework.org/topics/browsable-api/#customizing Commented Sep 27, 2016 at 5:52
  • @serg 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? Commented Sep 27, 2016 at 6:15
  • Have you figured out the way to do it now? Commented Apr 10, 2017 at 7:46

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

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

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.