[Fixed]-Django + DRF + Angular: app renders JSON response from auth package instead of redirecting

1👍

The login.html is a usual Django template so it doesn’t seem like you’re using Angular for login page. What django-rest-auth provides is a handful of API endpoints for authentication purpose, that return JSON.

You’re trying to do a POST from browser in foreground mode (non-AJAX), so browser shows you whatever that view returns – JSON. Endpoint does not take to account ?next.

This app assumes that you’re using Angular or other SPA, that would POST using AJAX to these endpoints and implement redirects to ?next and other features in Javascript. But not using API endpoint in <form> inside Django template.

Couple of options:

  • Implement auth views in Angular, that would use django-rest-auth endpoints. Or use boilerplate projects.

  • Use Django page, but point <form> to either Django’s default login view or a custom regular Django view that is not an API endpoint but returns text/html or redirects to ?next.

Leave a comment