This is how I do stuff: in urls.py: router.register(time', viewsets. TimeViewSet, 'time')
http://example.com/time/timedata/ class TimeViewSet(viewsets.GenericViewSet): @list_route(methods=['get'], permission_classes=[]) def timedata(self, request): data = { 'current_time' : timezone.now() } return Response(data) Obviously better to do stuff in a RESTful manner but this works for me. -Jeff On Mon, Jun 20, 2016 at 7:25 PM, 'Abraham Varricatt' via Django REST framework <[email protected]> wrote: > Hello, > > Is it possible to use Django Rest Framework (DRF) for something other than > models? Here's a trivial example, > > To make an API end point which returns the current server time (in JSON > format, eg: {"current_time": "XYZ"}). It can accept a string to indicate > timezone, and must accept both GET and POST. > > I can figure out how to do the above without DRF using regular Django urls > and views. What I can't figure out is how to use DRF for the same. > > From the docs, it looks best to use routers when making a DRF end-point. > Which means I need a structure like this, > > urls.py <-> router <-> Viewset <-> Serializer > > But as I understand Serilizers ( > http://www.django-rest-framework.org/api-guide/serializers/ ), they can > only be used for complex models or querysets - which is not what I need. > > I feel like I'm mis-understanding something about DRF. Help please? > > Puzzled, > Abraham V. > > -- > 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.
