[Django]-Is there a way for angular to get the current user when using basic login from django

3👍

OK, you can do something like that

Example (someUrl is url to your function in view.py):
In angular controller add $http

$http({method: 'POST', url: '/someUrl'}).
  success(function(data){
      //process aswer
  });

In djnago view.py:

from django.shortcuts import HttpResponse
import json

def check_login(request):
    if request.user.is_authenticated():
        return HttpResponse(json.dumps({'result': {'logged': True}, 'user':      request.user.username}),
                        content_type="application/json")
    else:
        return HttpResponse(json.dumps({'result': {'logged': False}}),
                        content_type="application/json")

Leave a comment