mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-05 13:00:12 +03:00
Added more common usage examples of including routers in urlpatterns.
This is an alternative to #2333.
This commit is contained in:
parent
e4c7c10b00
commit
73c38b0bcb
|
@ -21,6 +21,32 @@ Here's an example of a simple URL conf, that uses `SimpleRouter`.
|
||||||
router.register(r'accounts', AccountViewSet)
|
router.register(r'accounts', AccountViewSet)
|
||||||
urlpatterns = router.urls
|
urlpatterns = router.urls
|
||||||
|
|
||||||
|
A more common usage of routers is
|
||||||
|
|
||||||
|
from django.conf.urls import patterns, include, url
|
||||||
|
from rest_framework import routers
|
||||||
|
|
||||||
|
router = routers.SimpleRouter()
|
||||||
|
router.register(r'users', UserViewSet)
|
||||||
|
router.register(r'accounts', AccountViewSet)
|
||||||
|
|
||||||
|
urlpatterns = patterns('',
|
||||||
|
url(r'^', include(router.urls))
|
||||||
|
)
|
||||||
|
|
||||||
|
It is possible to namespace the router's views using Django's standard namespacing mechanism:
|
||||||
|
|
||||||
|
from django.conf.urls import patterns, include, url
|
||||||
|
from rest_framework import routers
|
||||||
|
|
||||||
|
router = routers.SimpleRouter()
|
||||||
|
router.register(r'users', UserViewSet)
|
||||||
|
router.register(r'accounts', AccountViewSet)
|
||||||
|
|
||||||
|
urlpatterns = patterns('',
|
||||||
|
url(r'^', include(router.urls, namespace='api'))
|
||||||
|
)
|
||||||
|
|
||||||
There are two mandatory arguments to the `register()` method:
|
There are two mandatory arguments to the `register()` method:
|
||||||
|
|
||||||
* `prefix` - The URL prefix to use for this set of routes.
|
* `prefix` - The URL prefix to use for this set of routes.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user