mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-23 01:57:00 +03:00
Added format_suffix_patterns, and fix up settings
This commit is contained in:
parent
149b00a070
commit
93189ec27d
|
@ -23,10 +23,10 @@ DEFAULTS = {
|
|||
'DEFAULT_RENDERERS': (
|
||||
renderers.JSONRenderer,
|
||||
renderers.JSONPRenderer,
|
||||
renderers.DocumentingHTMLRenderer,
|
||||
renderers.DocumentingXHTMLRenderer,
|
||||
# renderers.DocumentingHTMLRenderer,
|
||||
# renderers.DocumentingXHTMLRenderer,
|
||||
renderers.DocumentingPlainTextRenderer,
|
||||
renderers.XMLRenderer
|
||||
# renderers.XMLRenderer
|
||||
)
|
||||
}
|
||||
|
||||
|
|
20
djangorestframework/urlpatterns.py
Normal file
20
djangorestframework/urlpatterns.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from django.conf.urls.defaults import url
|
||||
|
||||
|
||||
def format_suffix_patterns(urlpatterns, suffix_required=False):
|
||||
"""
|
||||
Supplement existing urlpatterns with corrosponding patterns that also
|
||||
include a '.format' suffix. Retains urlpattern ordering.
|
||||
"""
|
||||
ret = []
|
||||
for urlpattern in urlpatterns:
|
||||
# Form our complementing '.format' urlpattern
|
||||
regex = urlpattern.regex.pattern.rstrip('$') + '.(?P<format>[a-z]+)$'
|
||||
view = urlpattern._callback or urlpattern._callback_str
|
||||
kwargs = urlpattern.default_args
|
||||
name = urlpattern.name
|
||||
# Add in both the existing and the new urlpattern
|
||||
if not suffix_required:
|
||||
ret.append(urlpattern)
|
||||
ret.append(url(regex, view, kwargs, name))
|
||||
return ret
|
|
@ -111,6 +111,7 @@ and
|
|||
|
||||
Now update the `urls.py` file slightly, to append a set of `format_suffix_patterns` in addition to the existing URLs.
|
||||
|
||||
from django.conf.urls import patterns, url
|
||||
from djangorestframework.urlpatterns import format_suffix_patterns
|
||||
|
||||
urlpatterns = patterns('blogpost.views',
|
||||
|
|
Loading…
Reference in New Issue
Block a user