mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-03 05:04:31 +03:00
More consistent examples
This commit is contained in:
parent
e7ca326555
commit
35331f5820
|
@ -29,8 +29,8 @@ Example:
|
||||||
|
|
||||||
urlpatterns = patterns('blog.views',
|
urlpatterns = patterns('blog.views',
|
||||||
url(r'^/$', 'api_root'),
|
url(r'^/$', 'api_root'),
|
||||||
url(r'^comment/$', 'comment_root'),
|
url(r'^comment/$', 'comment_list'),
|
||||||
url(r'^comment/(?P<pk>[0-9]+)/$', 'comment_instance')
|
url(r'^comment/(?P<pk>[0-9]+)/$', 'comment_detail')
|
||||||
)
|
)
|
||||||
|
|
||||||
urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json', 'html'])
|
urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json', 'html'])
|
||||||
|
@ -38,13 +38,12 @@ Example:
|
||||||
When using `format_suffix_patterns`, you must make sure to add the `'format'` keyword argument to the corresponding views. For example:
|
When using `format_suffix_patterns`, you must make sure to add the `'format'` keyword argument to the corresponding views. For example:
|
||||||
|
|
||||||
@api_view(('GET', 'POST'))
|
@api_view(('GET', 'POST'))
|
||||||
def api_root(request, format=None):
|
def comment_list(request, format=None):
|
||||||
# do stuff...
|
# do stuff...
|
||||||
|
|
||||||
Or with class based views:
|
Or with class based views:
|
||||||
|
|
||||||
class CommentList(APIView):
|
class CommentList(APIView):
|
||||||
|
|
||||||
def get(self, request, format=None):
|
def get(self, request, format=None):
|
||||||
# do stuff...
|
# do stuff...
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user