diff options
Diffstat (limited to 'django/shortcuts.py')
| -rw-r--r-- | django/shortcuts.py | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/django/shortcuts.py b/django/shortcuts.py index d1c0770af9..f3c07a6972 100644 --- a/django/shortcuts.py +++ b/django/shortcuts.py @@ -6,6 +6,9 @@ for convenience's sake. import warnings from django.template import loader, RequestContext +from django.template.context import _current_app_undefined +from django.template.engine import ( + _context_instance_undefined, _dictionary_undefined, _dirs_undefined) from django.http import HttpResponse, Http404 from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect from django.db.models.base import ModelBase @@ -16,49 +19,43 @@ from django.utils import six from django.utils.deprecation import RemovedInDjango20Warning -def render_to_response(*args, **kwargs): +def render_to_response(template_name, dictionary=_dictionary_undefined, + context_instance=_context_instance_undefined, + content_type=None, dirs=_dirs_undefined): """ Returns a HttpResponse whose content is filled with the result of calling django.template.loader.render_to_string() with the passed arguments. """ - httpresponse_kwargs = {'content_type': kwargs.pop('content_type', None)} - # TODO: refactor to avoid the deprecated code path. with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=RemovedInDjango20Warning) - content = loader.render_to_string(*args, **kwargs) + content = loader.render_to_string(template_name, dictionary, context_instance, dirs) - return HttpResponse(content, **httpresponse_kwargs) + return HttpResponse(content, content_type) -def render(request, *args, **kwargs): +def render(request, template_name, dictionary=_dictionary_undefined, + context_instance=_context_instance_undefined, + content_type=None, status=None, current_app=_current_app_undefined, + dirs=_dirs_undefined): """ Returns a HttpResponse whose content is filled with the result of calling django.template.loader.render_to_string() with the passed arguments. Uses a RequestContext by default. """ - httpresponse_kwargs = { - 'content_type': kwargs.pop('content_type', None), - 'status': kwargs.pop('status', None), - } - - if 'context_instance' in kwargs: - context_instance = kwargs.pop('context_instance') - if kwargs.get('current_app', None): + if context_instance is not _context_instance_undefined: + if current_app is not _current_app_undefined: raise ValueError('If you provide a context_instance you must ' 'set its current_app before calling render()') else: - current_app = kwargs.pop('current_app', None) context_instance = RequestContext(request, current_app=current_app) - kwargs['context_instance'] = context_instance - # TODO: refactor to avoid the deprecated code path. with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=RemovedInDjango20Warning) - content = loader.render_to_string(*args, **kwargs) + content = loader.render_to_string(template_name, dictionary, context_instance, dirs) - return HttpResponse(content, **httpresponse_kwargs) + return HttpResponse(content, content_type, status) def redirect(to, *args, **kwargs): |
