Python rest_framework.urlpatterns.format_suffix_patterns() Examples
The following are 2
code examples of rest_framework.urlpatterns.format_suffix_patterns().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
rest_framework.urlpatterns
, or try the search function
.
Example #1
Source File: routers.py From Dailyfresh-B2C with Apache License 2.0 | 6 votes |
def get_urls(self): """ Generate the list of URL patterns, including a default root view for the API, and appending `.json` style format suffixes. """ urls = super(DefaultRouter, self).get_urls() if self.include_root_view: view = self.get_api_root_view(api_urls=urls) root_url = url(r'^$', view, name=self.root_view_name) urls.append(root_url) if self.include_format_suffixes: urls = format_suffix_patterns(urls) return urls
Example #2
Source File: urls.py From kobo-predict with BSD 2-Clause "Simplified" License | 5 votes |
def get_urls(self): ret = [] if self.include_root_view: root_url = url(r'^$', self.get_api_root_view(), name=self.root_view_name) ret.append(root_url) for prefix, viewset, basename in self.registry: lookup = self.get_lookup_regex(viewset) lookup_list = self.get_lookup_regexes(viewset) if lookup_list: # lookup = lookups[0] lookup_list = [u'/'.join(k) for k in lookup_list] else: lookup_list = [u''] routes = self.get_routes(viewset) for route in routes: mapping = self.get_method_map(viewset, route.mapping) if not mapping: continue for lookups in lookup_list: regex = route.url.format( prefix=prefix, lookup=lookup, lookups=lookups, trailing_slash=self.trailing_slash, extra=self.get_extra_lookup_regexes(route) ) view = viewset.as_view(mapping, **route.initkwargs) name = route.name.format(basename=basename) ret.append(url(regex, view, name=name)) if self.include_format_suffixes: ret = format_suffix_patterns(ret, allowed=['[a-z0-9]+']) return ret