Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools

Bernardo Augusto García Loaiza
PLUS
Bernardo Augusto García Loaiza
Courses Plus Student 792 Points

What is the difference between use SimpleRouter() and DefaultRouter() classes?

In the video about of Relations, Kenneth did:

    router = routers.SimpleRouter()
    router.register(r'courses', views.CourseViewSet)
    router.register(r'reviews', views.ReviewViewSet)

    urlpatterns = [
        url(r'^admin/', admin.site.urls),
        url(r'^api-auth/', include('rest_framework.urls',
                               namespace='rest_framework')),
        url(r'^api/v1/courses/', include('courses.urls', namespace='courses')),
        url(r'^api/v2/', include(router.urls, namespace='apiv2')),
    ]

And I have been serializing my models of this way:

    router = routers.DefaultRouter()
    router.register(r'users', UserViewSet)
    router.register(r'teams', TeamViewSet)
    router.register(r'fields', FieldViewSet)
    router.register(r'matchs', MatchViewSet)

    urlpatterns = [
        url(r'^api/', include(router.urls)),
        url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
    ]

In this url http://www.django-rest-framework.org/api-guide/routers/ says:

This router is similar to SimpleRouter as above, but additionally includes a default API root view, that returns a response containing hyperlinks to all the list views. It also generates routes for optional .json style format suffixes.

[MOD: edited code blocks - srh]

Steven Parker
Steven Parker
231,236 Points

Did you mean to post this in the Python topic area?

2 Answers

Steven Parker
Steven Parker
231,236 Points

You can click on the little box with three dots, select "edit question" and then change the category.

Bernardo Augusto García Loaiza
PLUS
Bernardo Augusto García Loaiza
Courses Plus Student 792 Points

Thanks Steven Parker, I've already post again, Sorry I don't know that can edit the category. Can I delete this question here? Regards :)

Steven Parker
Steven Parker
231,236 Points

You can, but since you answered instead of commenting, you might need to delete your own answers first.