Monday, 23 September 2019

How to use the django rest-auth views with custom html templates instead of browserable APIs

I am using django rest-auth and allauth for a login/logout and registration on my website. These are very easy to use and work well. however, the browseable APIs are ugly for production. I want to fully customize my login view but still have the underlying rest-auth logic in place.

I was not able to find helpful tutorials on how to do this. I found this: https://wsvincent.com/django-user-authentication-tutorial-login-and-logout/ which is exactly what I want to do but with rest-auth rather than the build-in user authentication system that django offers.

How can I do this? is there a default .html files that I can override?

details

this is my app's urls.py:

urlpatterns = [
    path('users/', include('users.urls')),
    path('rest-auth/', include('rest_auth.urls')),
    path('rest-auth/registration/', include('rest_auth.registration.urls')),
]

the above have default views, I would like to overwrite their templates.

update

the way I got this to work is to overrode the LoginView in rest-auth with the following:

class CustomLoginView(LoginView):
    def get(self, request):
        return render(request, "api/test_template.html")

but now in test_template.html how do I make input fields that feed to the same inputs of rest-auth login automatically?



from How to use the django rest-auth views with custom html templates instead of browserable APIs

No comments:

Post a Comment