i have historic data that i want to publish via webservice by versions. To do that i'm using Django-Rest-Framework. I'm already using this framework to provide other services but now it seems to be a little bit harder to accomplished this goal.
The main goal is to provide a url:
http://127.0.0.1:8000/service/vocab (realtime) - done
http://127.0.0.1:8000/service/v1/vocab (version 1)
http://127.0.0.1:8000/service/v2/vocab (version 2)
http://127.0.0.1:8000/service/vn/vocab (version n)
for this i'm trying to config the DRF router to make this possible.
So the idea is something like this:
urls.py
router = routers.DefaultRouter()
router.register(r'vocab', views.VocabViewSet, 'vocabs')
router.register(r'{version}/vocab', views.VersionViewSet, 'vocab')
urlpatterns = patterns('',
...
url(r'^service/', include(router.urls))
)
views.py
class VersionViewSet(viewsets.ModelViewSet):
queryset = Version.objects.all()
serializer_class = VersionSerializer
@detail_route(methods=['post'], url_path='vocab')
def get_vocabs(self, request, version='v1'):
queryset = Version.objects.filter(version=version)
In this case it occurs :
invalid literal for int() with base 10: 'version'
That's because that DRF expects an int after service/.
I'm trying to find a solution to this case. Can you provide any hint how can i make this ?
Maybe Customize dynamic routes is the a good approach, what do you think ? If so, can you provide an example how to apply it in this case or similar?
Thanks in advance.