... | ... | @@ -49,14 +49,19 @@ api.acl.can_view(user) |
|
|
|
|
|
The URL system mainly works the same way as for any other app: a path or regular expression associated with a view (and some namespacing options) are provided in a `urlpatterns` variable.
|
|
|
|
|
|
The difference lies in the use of a "router" to build most of those urlpatterns. A router is an object that automatically register [viewsets](#the-viewsets) and generates urls based on it. It also builds a root page that presents all the registered urls in a nice way.
|
|
|
The difference lies in the use of a "router" to build most of those urlpatterns. A router is an object that automatically register [viewsets](#the-viewsets) and generates URLs based on it. It also builds a root page that presents all the registered URLs in a nice way. The `DefaultRouter` which is the most current DRF router used unfortunately is only meant to register viewsets thus only the URLs that corresponds to the viewsets and not the "more simple" views. To fix that a custom router `api.routers.AllViewsRouter` has been added. It acts nearly the same as the `DefaultRouter` except that one can do the following to register views:
|
|
|
* For a view:
|
|
|
```python
|
|
|
router.register_view(r'<pattern>', path.to.view, name='<optional_name_to_refer_to>')
|
|
|
```
|
|
|
|
|
|
* For a viewset:
|
|
|
```python
|
|
|
router.register_viewset(r'<pattern>', path.to.viewset, base_name='<alternative_name>')
|
|
|
```
|
|
|
|
|
|
To register a new URL, add a line structured like that (:
|
|
|
```python
|
|
|
router.register(r'<url>', path.to.viewset, base_name='<alternative_name>')
|
|
|
```
|
|
|
|
|
|
The `base_name` parameter is optional, it is used as a base to generate the name of the url. The generated url can be later referenced with the names `<base_name>-list` and `<base_name>-details`. By default, if not specified, `base_name` will be determined from the model's name of the viewset's queryset. For instance, if a viewset uses the queryset
|
|
|
For a view, the `name` parameter is the optional similar parameter used for standard urls. In the case of a viewset, the `base_name` parameter is optional, it is used as a base to generate the name of the url. The generated url can be later referenced with the names `<base_name>-list` and `<base_name>-details`. By default, if not specified, `base_name` will be determined from the model's name of the viewset's queryset. For instance, if a viewset uses the queryset
|
|
|
```
|
|
|
queryset = users.model.User.objects.all()
|
|
|
```
|
... | ... | |