You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Use createsuperuser email and username flags
* Only remove db.sqlite3
* Remove global permission class
This interferes with Core API schema endpoint
* Add default pagination class
* Specify changes made in snippets/urls.py
* Auth urls were already set in tutorial/urls.py
* Specify changes made in snippets/urls.py
* Use the suggested admin username from quickstart
* Move global pagination setting away from quickstart section
Copy file name to clipboardExpand all lines: docs/tutorial/5-relationships-and-hyperlinked-apis.md
+3-8Lines changed: 3 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -130,23 +130,18 @@ After adding all those names into our URLconf, our final `snippets/urls.py` file
130
130
name='user-detail')
131
131
])
132
132
133
-
# Login and logout views for the browsable API
134
-
urlpatterns += [
135
-
url(r'^api-auth/', include('rest_framework.urls',
136
-
namespace='rest_framework')),
137
-
]
138
-
139
133
## Adding pagination
140
134
141
135
The list views for users and code snippets could end up returning quite a lot of instances, so really we'd like to make sure we paginate the results, and allow the API client to step through each of the individual pages.
142
136
143
-
We can change the default list style to use pagination, by modifying our `tutorial/settings.py` file slightly. Add the following setting:
137
+
We can change the default list style to use pagination, by modifying our `tutorial/settings.py` file slightly. Add the following setting:
Note that settings in REST framework are all namespaced into a single dictionary setting, named 'REST_FRAMEWORK', which helps keep them well separated from your other project settings.
144
+
Note that settings in REST framework are all namespaced into a single dictionary setting, named `REST_FRAMEWORK`, which helps keep them well separated from your other project settings.
150
145
151
146
We could also customize the pagination style if we needed too, but in this case we'll just stick with the default.
Copy file name to clipboardExpand all lines: docs/tutorial/6-viewsets-and-routers.md
+4-6Lines changed: 4 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,7 @@ The URLs for custom actions by default depend on the method name itself. If you
61
61
The handler methods only get bound to the actions when we define the URLConf.
62
62
To see what's going on under the hood let's first explicitly create a set of views from our ViewSets.
63
63
64
-
In the `urls.py` file we bind our `ViewSet` classes into a set of concrete views.
64
+
In the `snippets/urls.py` file we bind our `ViewSet` classes into a set of concrete views.
65
65
66
66
from snippets.views import SnippetViewSet, UserViewSet, api_root
67
67
from rest_framework import renderers
@@ -103,22 +103,20 @@ Now that we've bound our resources into concrete views, we can register the view
103
103
104
104
Because we're using `ViewSet` classes rather than `View` classes, we actually don't need to design the URL conf ourselves. The conventions for wiring up resources into views and urls can be handled automatically, using a `Router` class. All we need to do is register the appropriate view sets with a router, and let it do the rest.
105
105
106
-
Here's our re-wired `urls.py` file.
106
+
Here's our re-wired `snippets/urls.py` file.
107
107
108
108
from django.conf.urls import url, include
109
-
from snippets import views
110
109
from rest_framework.routers import DefaultRouter
110
+
from snippets import views
111
111
112
112
# Create a router and register our viewsets with it.
Registering the viewsets with the router is similar to providing a urlpattern. We include two arguments - the URL prefix for the views, and the viewset itself.
Once you've set up a database and initial user created and ready to go, open up the app's directory and we'll get coding...
60
60
@@ -134,20 +134,13 @@ Finally, we're including default login and logout views for use with the browsab
134
134
135
135
## Settings
136
136
137
-
We'd also like to set a few global settings. We'd like to turn on pagination, and we want our API to only be accessible to admin users. The settings module will be in `tutorial/settings.py`
137
+
Add `'rest_framework'`to `INSTALLED_APPS`. The settings module will be in `tutorial/settings.py`
0 commit comments