In my python rest api application, I have successfully included the django oauth2 toolkit and I am getting accesstoken while logging in. Now I have to write an api to get the details of the current logged in user and his group information and the group permissions.
My urls.py
url(r'me', get_me),
My serialzers.py
class UserGroupSerializer(serializers.ModelSerializer):
permissions = serializers.SerializerMethodField(required=False)
groups = serializers.SerializerMethodField(required=False)
def get_groups(self, obj):
group_list = []
for group in obj.groups.all():
group_list.append(group.name)
return group_list
def get_permissions(self, obj):
permissions = []
for group in obj.groups.all():
group_permissions = group.permissions.all().values_list('codename', flat=True)
for group_permission in group_permissions:
permissions.append(group_permission)
return permissions
class Meta:
model = get_user_model()
exclude = ('password','user_permissions',)
#fields = '__all__'
My views.py
def get_me(request):
user = request.user
return {
'user': UserGroupSerializer(user).data,
}
When I call this api, I am getting the following error,
The view account.views.get_me didn't return an HttpResponse object. It returned None instead.
What is the issue? Is it the correct method am following?