Re:Flask vs. Django: Worksheet to choose the right framework
by jhgg on Thursday April 23, 2015 @02:09PM
(#9428629)
It's not true at all. I've done nested routers in DRF plenty of times.
router = DefaultRouter()
router.register('users/(?P<user_id>\d+)/teams', UserTeamViewSet)
You can then access user_id via self.kwargs['user_id'] from within the viewset. And the team ID is implicitly added by the router to support list (and update), and retrieve (delete, put, patch) methods. user_id is also passed as a kwarg to the dispatched method (create, retrieve, etc...)
Re:Flask vs. Django: Worksheet to choose the right framework
by asmosoinio on Thursday April 23, 2015 @02:11PM
(#9428646)
I don't get it either. The route definition is just an url with two arguments, right? Maybe I'm missing something...
Re:Flask vs. Django: Worksheet to choose the right framework
by mpdehaan2 on Thursday April 23, 2015 @02:14PM
(#9428681)
I ended up extending DJRF to do nested collections, but I'd argue your REST topology would be better with one canonical resource and unique team IDs:
/teams/<id>/
It's fine to be able to add a user to a team by posting to a subcollection though, but there should only be one URL for the resource (IMHO).
Re:Flask vs. Django: Worksheet to choose the right framework
by welder on Thursday April 23, 2015 @03:17PM
(#9429148)
drf-nested-routers only works with the most basic Fields. For example:
https://github.com/alanjds/drf-nested-routers/issues
Right now it's a hack that limits your api features, but might change in the future.
> Flask > Django for APIs. For example, a nested api resource in Flask is
> @app.route('/users/<string:user_id>/teams/<string:team_id>', methods=['GET', 'POST'])
> while with Django REST framework this is impossible.
> (drf-nested-routers helps but breaks unless you use only the most basic Django REST framework features.
Is this really true? For a start I've managed to build a complex app without needing nested routers (although they are cool). Second - I've used DRF extensions nested routers without finding any problems.
For me needing an API is a point in favour of using Django for a lot of use cases - you get an elegant declarative syntax and lots of batteries included.