aboutsummaryrefslogtreecommitdiffstats
path: root/examples/blogpost
diff options
context:
space:
mode:
authorTom Christie2011-04-25 04:48:55 +0100
committerTom Christie2011-04-25 04:48:55 +0100
commit84a4fd3ea11a55441cb5b8acd584c76fc325edcc (patch)
tree5ef40c22379166cfb58b3c45190e9ba60f006fdd /examples/blogpost
parent4692374e0d6f020f8a7a95f3a60094d525c59341 (diff)
downloaddjango-rest-framework-84a4fd3ea11a55441cb5b8acd584c76fc325edcc.tar.bz2
tidy up
Diffstat (limited to 'examples/blogpost')
0 files changed, 0 insertions, 0 deletions
ss="gu">## format_suffix_patterns **Signature**: format_suffix_patterns(urlpatterns, suffix_required=False, allowed=None) Returns a URL pattern list which includes format suffix patterns appended to each of the URL patterns provided. Arguments: * **urlpatterns**: Required. A URL pattern list. * **suffix_required**: Optional. A boolean indicating if suffixes in the URLs should be optional or mandatory. Defaults to `False`, meaning that suffixes are optional by default. * **allowed**: Optional. A list or tuple of valid format suffixes. If not provided, a wildcard format suffix pattern will be used. Example: from rest_framework.urlpatterns import format_suffix_patterns urlpatterns = patterns('blog.views', url(r'^/$', 'api_root'), url(r'^comment/$', 'comment_root'), url(r'^comment/(?P<pk>[0-9]+)/$', 'comment_instance') ) urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json', 'html']) When using `format_suffix_patterns`, you must make sure to add the `'format'` keyword argument to the corresponding views. For example. @api_view(('GET',)) def api_root(request, format=None): # do stuff... The name of the kwarg used may be modified by using the `FORMAT_SUFFIX_KWARG` setting. Also note that `format_suffix_patterns` does not support descending into `include` URL patterns. --- ## Accept headers vs. format suffixes There seems to be a view among some of the Web community that filename extensions are not a RESTful pattern, and that `HTTP Accept` headers should always be used instead. It is actually a misconception. For example, take the following quote from Roy Fielding discussing the relative merits of query parameter media-type indicators vs. file extension media-type indicators: &ldquo;That's why I always prefer extensions. Neither choice has anything to do with REST.&rdquo; &mdash; Roy Fielding, [REST discuss mailing list][cite2] The quote does not mention Accept headers, but it does make it clear that format suffixes should be considered an acceptable pattern. [cite]: http://tech.groups.yahoo.com/group/rest-discuss/message/5857 [cite2]: http://tech.groups.yahoo.com/group/rest-discuss/message/14844