我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用django.conf.settings.REST_FRAMEWORK。
def api_quota(self): '''Get's the amount of requests this user has made in the last 24 hours as well as the maximum allowed by DRF's throttling framework''' hits = cache.get('throttle_user_{0}'.format(self.user.id)) used = len(hits) if hits else 0 allowed = settings.REST_FRAMEWORK['DEFAULT_THROTTLE_RATES']['user'] return {'used': used, 'allowed': allowed}
def get_metadata_from_viewset(self, viewset): if isinstance(viewset, dict): output = viewset else: MetadataClass = import_string(django_settings.REST_FRAMEWORK['DEFAULT_METADATA_CLASS']) output = MetadataClass().determine_metadata(None, viewset) return output
def rebuild_index(self): MetadataClass = import_string(django_settings.REST_FRAMEWORK['DEFAULT_METADATA_CLASS']) context = {} directory = os.path.join(django_settings.BASE_DIR, settings.FRONT_APPLICATION_PATH, 'app', 'data') context['items'] = self.walk_dir(directory, True) context['root_metadata'] = self.render( MetadataClass().determine_metadata(None, 'APIRootView') ) self.write_file(context, directory, 'index.js', self.index_template_name, True)
def paginated_queryset(queryset, request, pagination_class=PageNumberPagination()): ''' Return a paginated result for a queryset ''' paginator = pagination_class paginator.page_size = settings.REST_FRAMEWORK['PAGE_SIZE'] result_page = paginator.paginate_queryset(queryset, request) return (paginator, result_page)