'Add Django Rest Framework Login Button to Browsable API when Using Third Party Auth Library (django-rest-knox)
The login button is missing from my browsable API. I am using django-rest-knox for token authentication. My urls.py contains:
urlpatterns = [
path('admin/', admin.site.urls),
path(r'', include(router.urls)),
path('auth/', include('knox.urls'))
]
And to allow for using BasicAuthentication on the login view itself I have this in my settings.py
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
'knox.auth.TokenAuthentication',
)
}
I had a little dig into DRF code on github and this is the template tag:
@register.simple_tag
def optional_login(request):
"""
Include a login snippet if REST framework's login view is in the URLconf.
"""
try:
login_url = reverse('rest_framework:login')
except NoReverseMatch:
return ''
In the browsable API, the login button is only shown when the exception is not thrown. But I don't know how to get that reverseMatch. Can I rename my login URL? Or override the template tag? Or some other way to get me a login button? Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
