From 047bec1288040b9f387e4977bb6cb3fd00d8ea40 Mon Sep 17 00:00:00 2001 From: Code Apprentice Date: Thu, 4 Jan 2024 07:16:57 -0700 Subject: [PATCH] Add documentation to show how to add authentication for the browseable api (#9137) --- docs/topics/browsable-api.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/topics/browsable-api.md b/docs/topics/browsable-api.md index 39473cdd8..67bc97890 100644 --- a/docs/topics/browsable-api.md +++ b/docs/topics/browsable-api.md @@ -15,6 +15,18 @@ If you include fully-qualified URLs in your resource output, they will be 'urliz By default, the API will return the format specified by the headers, which in the case of the browser is HTML. The format can be specified using `?format=` in the request, so you can look at the raw JSON response in a browser by adding `?format=json` to the URL. There are helpful extensions for viewing JSON in [Firefox][ffjsonview] and [Chrome][chromejsonview]. +## Authentication + +To quickly add authentication to the browesable api, add a routes named `"login"` and `"logout"` under the namespace `"rest_framework"`. DRF provides default routes for this which you can add to your urlconf: + +```python +urlpatterns = [ + // ... + url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')) +] +``` + + ## Customizing The browsable API is built with [Twitter's Bootstrap][bootstrap] (v 3.4.1), making it easy to customize the look-and-feel.