Skip to content

Commit bf8e71c

Browse files
committed
Merge pull request #1 from tomchristie/master
Update from main
2 parents fa9f5fb + 5fa1002 commit bf8e71c

34 files changed

+405
-90
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
.*
55

66
html/
7+
htmlcov/
78
coverage/
89
build/
910
dist/

README.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ Django REST framework is a powerful and flexible toolkit that makes it easy to b
1212

1313
Some reasons you might want to use REST framework:
1414

15-
* The Web browseable API is a huge useability win for your developers.
16-
* Authentication policies including OAuth1a and OAuth2 out of the box.
17-
* Serialization that supports both ORM and non-ORM data sources.
18-
* Customizable all the way down - just use regular function-based views if you don't need the more powerful features.
19-
* Extensive documentation, and great community support.
15+
* The [Web browseable API][sandbox] is a huge useability win for your developers.
16+
* [Authentication policies][authentication] including [OAuth1a][oauth1-section] and [OAuth2][oauth2-section] out of the box.
17+
* [Serialization][serializers] that supports both [ORM][modelserializer-section] and [non-ORM][serializer-section] data sources.
18+
* Customizable all the way down - just use [regular function-based views][functionview-section] if you don't need the [more][generic-views] [powerful][viewsets] [features][routers].
19+
* [Extensive documentation][index], and [great community support][group].
2020

2121
There is a live example API for testing purposes, [available here][sandbox].
2222

@@ -139,6 +139,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
139139
[group]: https://groups.google.com/forum/?fromgroups#!forum/django-rest-framework
140140
[0.4]: https://github.com/tomchristie/django-rest-framework/tree/0.4.X
141141
[sandbox]: http://restframework.herokuapp.com/
142+
143+
[index]: http://django-rest-framework.org/
144+
[oauth1-section]: http://django-rest-framework.org/api-guide/authentication.html#oauthauthentication
145+
[oauth2-section]: http://django-rest-framework.org/api-guide/authentication.html#oauth2authentication
146+
[serializer-section]: http://django-rest-framework.org/api-guide/serializers.html#serializers
147+
[modelserializer-section]: http://django-rest-framework.org/api-guide/serializers.html#modelserializer
148+
[functionview-section]: http://django-rest-framework.org/api-guide/views.html#function-based-views
149+
[generic-views]: http://django-rest-framework.org/api-guide/generic-views.html
150+
[viewsets]: http://django-rest-framework.org/api-guide/viewsets.html
151+
[routers]: http://django-rest-framework.org/api-guide/routers.html
152+
[serializers]: http://django-rest-framework.org/api-guide/serializers.html
153+
[authentication]: http://django-rest-framework.org/api-guide/authentication.html
154+
142155
[rest-framework-2-announcement]: http://django-rest-framework.org/topics/rest-framework-2-announcement.html
143156
[2.1.0-notes]: https://groups.google.com/d/topic/django-rest-framework/Vv2M0CMY9bg/discussion
144157
[image]: http://django-rest-framework.org/img/quickstart.png

docs/api-guide/authentication.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ HTTP digest authentication is a widely implemented scheme that was intended to r
355355

356356
The [Django OAuth Toolkit][django-oauth-toolkit] package provides OAuth 2.0 support, and works with Python 2.7 and Python 3.3+. The package is maintained by [Evonove][evonove] and uses the excelllent [OAuthLib][oauthlib]. The package is well documented, and comes as a recommended alternative for OAuth 2.0 support.
357357

358+
## Django OAuth2 Consumer
359+
360+
The [Django OAuth2 Consumer][doac] library from [Rediker Software][rediker] is another package that provides [OAuth 2.0 support for REST framework][doac-rest-framework]. The package includes token scoping permissions on tokens, which allows finer-grained access to your API.
361+
358362
[cite]: http://jacobian.org/writing/rest-worst-practices/
359363
[http401]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.2
360364
[http403]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.4
@@ -376,3 +380,6 @@ The [Django OAuth Toolkit][django-oauth-toolkit] package provides OAuth 2.0 supp
376380
[django-oauth-toolkit]: https://github.com/evonove/django-oauth-toolkit
377381
[evonove]: https://github.com/evonove/
378382
[oauthlib]: https://github.com/idan/oauthlib
383+
[doac]: https://github.com/Rediker-Software/doac
384+
[rediker]: https://github.com/Rediker-Software
385+
[doac-rest-framework]: https://github.com/Rediker-Software/doac/blob/master/docs/markdown/integrations.md#

docs/api-guide/generic-views.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ May be overridden to provide dynamic behavior such as returning a queryset that
9292
For example:
9393

9494
def get_queryset(self):
95-
return self.user.accounts.all()
95+
user = self.request.user
96+
return user.accounts.all()
9697

9798
#### `get_object(self)`
9899

docs/api-guide/responses.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ REST framework supports HTTP content negotiation by providing a `Response` class
1010

1111
The `Response` class subclasses Django's `SimpleTemplateResponse`. `Response` objects are initialised with data, which should consist of native Python primitives. REST framework then uses standard HTTP content negotiation to determine how it should render the final response content.
1212

13-
There's no requirement for you to use the `Response` class, you can also return regular `HttpResponse` objects from your views if you want, but it provides a nicer interface for returning Web API responses.
13+
There's no requirement for you to use the `Response` class, you can also return regular `HttpResponse` or `StreamingHttpResponse` objects from your views if required. Using the `Response` class simply provides a nicer interface for returning content-negotiated Web API responses, that can be rendered to multiple formats.
1414

1515
Unless you want to heavily customize REST framework for some reason, you should always use an `APIView` class or `@api_view` function for views that return `Response` objects. Doing so ensures that the view can perform content negotiation and select the appropriate renderer for the response, before it is returned from the view.
1616

docs/api-guide/routers.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ There are two mandatory arguments to the `register()` method:
2626

2727
Optionally, you may also specify an additional argument:
2828

29-
* `base_name` - The base to use for the URL names that are created. If unset the basename will be automatically generated based on the `model` or `queryset` attribute on the viewset, if it has one.
29+
* `base_name` - The base to use for the URL names that are created. If unset the basename will be automatically generated based on the `model` or `queryset` attribute on the viewset, if it has one. Note that if the viewset does not include a `model` or `queryset` attribute then you must set `base_name` when registering the viewset.
3030

3131
The example above would generate the following URL patterns:
3232

@@ -98,21 +98,45 @@ As with `SimpleRouter` the trailing slashs on the URL routes can be removed by s
9898

9999
Implementing a custom router isn't something you'd need to do very often, but it can be useful if you have specific requirements about how the your URLs for your API are strutured. Doing so allows you to encapsulate the URL structure in a reusable way that ensures you don't have to write your URL patterns explicitly for each new view.
100100

101-
The simplest way to implement a custom router is to subclass one of the existing router classes. The `.routes` attribute is used to template the URL patterns that will be mapped to each viewset.
101+
The simplest way to implement a custom router is to subclass one of the existing router classes. The `.routes` attribute is used to template the URL patterns that will be mapped to each viewset. The `.routes` attribute is a list of `Route` named tuples.
102+
103+
The arguments to the `Route` named tuple are:
104+
105+
**url**: A string representing the URL to be routed. May include the following format strings:
106+
107+
* `{prefix}` - The URL prefix to use for this set of routes.
108+
* `{lookup}` - The lookup field used to match against a single instance.
109+
* `{trailing_slash}` - Either a '/' or an empty string, depending on the `trailing_slash` argument.
110+
111+
**mapping**: A mapping of HTTP method names to the view methods
112+
113+
**name**: The name of the URL as used in `reverse` calls. May include the following format string:
114+
115+
* `{basename}` - The base to use for the URL names that are created.
116+
117+
**initkwargs**: A dictionary of any additional arguments that should be passed when instantiating the view. Note that the `suffix` argument is reserved for identifying the viewset type, used when generating the view name and breadcrumb links.
102118

103119
## Example
104120

105121
The following example will only route to the `list` and `retrieve` actions, and does not use the trailing slash convention.
106122

107123
class ReadOnlyRouter(SimpleRouter):
108124
"""
109-
A router for read-only APIs, which doesn't use trailing suffixes.
125+
A router for read-only APIs, which doesn't use trailing slashes.
110126
"""
111127
routes = [
112-
(r'^{prefix}$', {'get': 'list'}, '{basename}-list'),
113-
(r'^{prefix}/{lookup}$', {'get': 'retrieve'}, '{basename}-detail')
128+
Route(url=r'^{prefix}$',
129+
mapping={'get': 'list'},
130+
name='{basename}-list',
131+
initkwargs={'suffix': 'List'}),
132+
Route(url=r'^{prefix}/{lookup}$',
133+
mapping={'get': 'retrieve'},
134+
name='{basename}-detail',
135+
initkwargs={'suffix': 'Detail'})
114136
]
115137

138+
The `SimpleRouter` class provides another example of setting the `.routes` attribute.
139+
116140
## Advanced custom routers
117141

118142
If you want to provide totally custom behavior, you can override `BaseRouter` and override the `get_urls(self)` method. The method should insect the registered viewsets and return a list of URL patterns. The registered prefix, viewset and basename tuples may be inspected by accessing the `self.registry` attribute.

docs/css/default.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,7 @@ table {
303303
border-color: white;
304304
margin-bottom: 0.6em;
305305
}
306+
307+
.side-nav {
308+
overflow-y: scroll;
309+
}

docs/img/apiary.png

54.3 KB
Loading

docs/img/cerulean.png

61.1 KB
Loading

docs/img/django-rest-swagger.png

75.1 KB
Loading

docs/img/rest-framework-docs.png

74.8 KB
Loading

docs/img/self-describing.png

52.7 KB
Loading

docs/img/slate.png

64.2 KB
Loading

docs/index.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ Django REST framework is a powerful and flexible toolkit that makes it easy to b
1515

1616
Some reasons you might want to use REST framework:
1717

18-
* The Web browseable API is a huge usability win for your developers.
19-
* Authentication policies including OAuth1a and OAuth2 out of the box.
20-
* Serialization that supports both ORM and non-ORM data sources.
21-
* Customizable all the way down - just use regular function-based views if you don't need the more powerful features.
22-
* Extensive documentation, and great community support.
18+
* The [Web browseable API][sandbox] is a huge usability win for your developers.
19+
* [Authentication policies][authentication] including [OAuth1a][oauth1-section] and [OAuth2][oauth2-section] out of the box.
20+
* [Serialization][serializers] that supports both [ORM][modelserializer-section] and [non-ORM][serializer-section] data sources.
21+
* Customizable all the way down - just use [regular function-based views][functionview-section] if you don't need the [more][generic-views] [powerful][viewsets] [features][routers].
22+
* [Extensive documentation][index], and [great community support][group].
2323

2424
There is a live example API for testing purposes, [available here][sandbox].
2525

@@ -170,6 +170,7 @@ The API guide is your complete reference manual to all the functionality provide
170170

171171
General guides to using REST framework.
172172

173+
* [Documenting your API][documenting-your-api]
173174
* [AJAX, CSRF & CORS][ajax-csrf-cors]
174175
* [Browser enhancements][browser-enhancements]
175176
* [The Browsable API][browsableapi]
@@ -250,6 +251,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
250251
[django-oauth2-provider]: https://github.com/caffeinehit/django-oauth2-provider
251252
[0.4]: https://github.com/tomchristie/django-rest-framework/tree/0.4.X
252253
[image]: img/quickstart.png
254+
[index]: .
255+
[oauth1-section]: api-guide/authentication.html#oauthauthentication
256+
[oauth2-section]: api-guide/authentication.html#oauth2authentication
257+
[serializer-section]: api-guide/serializers.html#serializers
258+
[modelserializer-section]: api-guide/serializers.html#modelserializer
259+
[functionview-section]: api-guide/views.html#function-based-views
253260
[sandbox]: http://restframework.herokuapp.com/
254261

255262
[quickstart]: tutorial/quickstart.md
@@ -283,6 +290,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
283290
[status]: api-guide/status-codes.md
284291
[settings]: api-guide/settings.md
285292

293+
[documenting-your-api]: topics/documenting-your-api.md
286294
[ajax-csrf-cors]: topics/ajax-csrf-cors.md
287295
[browser-enhancements]: topics/browser-enhancements.md
288296
[browsableapi]: topics/browsable-api.md

docs/template.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
<li class="dropdown">
9696
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Topics <b class="caret"></b></a>
9797
<ul class="dropdown-menu">
98+
<li><a href="{{ base_url }}/topics/documenting-your-api{{ suffix }}">Documenting your API</a></li>
9899
<li><a href="{{ base_url }}/topics/ajax-csrf-cors{{ suffix }}">AJAX, CSRF & CORS</a></li>
99100
<li><a href="{{ base_url }}/topics/browser-enhancements{{ suffix }}">Browser enhancements</a></li>
100101
<li><a href="{{ base_url }}/topics/browsable-api{{ suffix }}">The Browsable API</a></li>
@@ -198,5 +199,14 @@ <h3 id="myModalLabel">Documentation search</h3>
198199
$('.dropdown-menu').on('click touchstart', function(event) {
199200
event.stopPropagation();
200201
});
202+
203+
// Dynamically force sidenav to no higher than browser window
204+
$('.side-nav').css('max-height', window.innerHeight - 130);
205+
206+
$(function(){
207+
$(window).resize(function(){
208+
$('.side-nav').css('max-height', window.innerHeight - 130);
209+
});
210+
});
201211
</script>
202212
</body></html>

0 commit comments

Comments
 (0)