Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
216,012 Points

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

2 Answers

Steven Parker
Steven Parker
216,012 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
216,012 Points

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