mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-26 16:09:49 +03:00
Support custom Context Class in renderers
This commit is contained in:
parent
8ecd419df7
commit
448932c659
|
@ -10,7 +10,7 @@ import copy
|
||||||
import string
|
import string
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.http.multipartparser import parse_header
|
from django.http.multipartparser import parse_header
|
||||||
from django.template import RequestContext, loader, Template
|
from django.template import loader, Template
|
||||||
from django.utils import simplejson as json
|
from django.utils import simplejson as json
|
||||||
from rest_framework.compat import yaml
|
from rest_framework.compat import yaml
|
||||||
from rest_framework.exceptions import ConfigurationError
|
from rest_framework.exceptions import ConfigurationError
|
||||||
|
@ -29,6 +29,8 @@ class BaseRenderer(object):
|
||||||
and `format` attributes, and override the `.render()` method.
|
and `format` attributes, and override the `.render()` method.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
context_class = api_settings.DEFAULT_CONTEXT_CLASS
|
||||||
|
|
||||||
media_type = None
|
media_type = None
|
||||||
format = None
|
format = None
|
||||||
|
|
||||||
|
@ -197,7 +199,7 @@ class TemplateHTMLRenderer(BaseRenderer):
|
||||||
def resolve_context(self, data, request, response):
|
def resolve_context(self, data, request, response):
|
||||||
if response.exception:
|
if response.exception:
|
||||||
data['status_code'] = response.status_code
|
data['status_code'] = response.status_code
|
||||||
return RequestContext(request, data)
|
return self.context_class(request, data)
|
||||||
|
|
||||||
def get_template_names(self, response, view):
|
def get_template_names(self, response, view):
|
||||||
if response.template_name:
|
if response.template_name:
|
||||||
|
@ -433,7 +435,7 @@ class BrowsableAPIRenderer(BaseRenderer):
|
||||||
breadcrumb_list = get_breadcrumbs(request.path)
|
breadcrumb_list = get_breadcrumbs(request.path)
|
||||||
|
|
||||||
template = loader.get_template(self.template)
|
template = loader.get_template(self.template)
|
||||||
context = RequestContext(request, {
|
context = self.context_class(request, {
|
||||||
'content': content,
|
'content': content,
|
||||||
'view': view,
|
'view': view,
|
||||||
'request': request,
|
'request': request,
|
||||||
|
|
|
@ -55,6 +55,9 @@ DEFAULTS = {
|
||||||
'anon': None,
|
'anon': None,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'DEFAULT_CONTEXT_CLASS':
|
||||||
|
'django.template.RequestContext',
|
||||||
|
|
||||||
# Pagination
|
# Pagination
|
||||||
'PAGINATE_BY': None,
|
'PAGINATE_BY': None,
|
||||||
'PAGINATE_BY_PARAM': None,
|
'PAGINATE_BY_PARAM': None,
|
||||||
|
@ -84,6 +87,7 @@ IMPORT_STRINGS = (
|
||||||
'DEFAULT_AUTHENTICATION_CLASSES',
|
'DEFAULT_AUTHENTICATION_CLASSES',
|
||||||
'DEFAULT_PERMISSION_CLASSES',
|
'DEFAULT_PERMISSION_CLASSES',
|
||||||
'DEFAULT_THROTTLE_CLASSES',
|
'DEFAULT_THROTTLE_CLASSES',
|
||||||
|
'DEFAULT_CONTEXT_CLASS',
|
||||||
'DEFAULT_CONTENT_NEGOTIATION_CLASS',
|
'DEFAULT_CONTENT_NEGOTIATION_CLASS',
|
||||||
'DEFAULT_MODEL_SERIALIZER_CLASS',
|
'DEFAULT_MODEL_SERIALIZER_CLASS',
|
||||||
'DEFAULT_PAGINATION_SERIALIZER_CLASS',
|
'DEFAULT_PAGINATION_SERIALIZER_CLASS',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user