1

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.

1

0

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.