Depends what you want to archive. If you just want the users, you could do:
users = User.objects.all() Remember to import User model ons. 12. sep. 2018 kl. 22.45 skrev Daniel Breves <[email protected]>: > I've just realized that I'm receiving a list of OrderedDict and that's ok. > But am I doing it the right way? > > On Wednesday, September 12, 2018 at 5:25:04 PM UTC-3, Daniel Breves wrote: >> >> Hi, there! >> >> I'm new in DRF and I created a Django project with two apps: one for a >> REST API and one for the frontend. I've created the API and it's working >> good, but now, I'd like to call the API from the frontend app. >> >> My code: >> >> views.py from api: >> >> class UserViewSet(viewsets.ModelViewSet): >> """ >> API endpoint that allows users to be viewd or edited. >> """ >> queryset = User.objects.all().order_by('-date_joined') >> serializer_class = UserSerializer >> >> views.py from frontend: >> >> def home(request): >> >> user_view_set = UserViewSet.as_view({'get':'list'}) >> response = user_view_set(request) >> users = response.data >> return render(request, 'index.html', {"users":users}) >> >> Doing that I can obtain the data, but it's in a strange format. So, I >> think that I'm doing something wrong. I'd like to obtain the JSON response. >> >> Can someone please help me with that? >> >> thank you very much! >> > -- > You received this message because you are subscribed to the Google Groups > "Django REST framework" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django REST framework" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
