How to register an @api_view with a router?

138 views
Skip to first unread message

Kenshi Kawaguchi

unread,
Mar 11, 2015, 3:03:29 PM3/11/15
to django-res...@googlegroups.com
It's unclear from the documentation, how to register a function based @api_view with a Router.  I'm seeing it in the registry, but there are no associated urls.  What's the proper way to do this? 

from django.conf import settings
settings
.configure(DEBUG=True, TEMPLATE_DEBUG=True)


from rest_framework.routers import SimpleRouter
from rest_framework.decorators import api_view


@api_view
def hello(request):
   
return "Hello World"


router
= SimpleRouter()
router
.register(r'hello', hello, base_name='bar')
print "urls: %s" % router.urls
print "registry: %s" % router.registry

Prints:

urls: []
registry: [('hello', <function decorator at 0x1027a2b18>, 'bar')]




Reply all
Reply to author
Forward
0 new messages