mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Added a request argument to render_to_string.
This is for consistency with Template.render. It adds a little bit of knowledge about HTTP requests in django.template.loader but I think consistency trumps purity.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from django.test import override_settings, SimpleTestCase
|
||||
from django.test.client import RequestFactory
|
||||
from django.template import TemplateDoesNotExist
|
||||
from django.template.loader import (
|
||||
get_template, select_template, render_to_string)
|
||||
@@ -10,6 +11,11 @@ from django.template.loader import (
|
||||
}, {
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.request',
|
||||
],
|
||||
},
|
||||
}])
|
||||
class TemplateLoaderTests(SimpleTestCase):
|
||||
|
||||
@@ -66,6 +72,11 @@ class TemplateLoaderTests(SimpleTestCase):
|
||||
content = render_to_string("template_loader/goodbye.html")
|
||||
self.assertEqual(content, "Goodbye! (Django templates)\n")
|
||||
|
||||
def test_render_to_string_with_request(self):
|
||||
request = RequestFactory().get('/foobar/')
|
||||
content = render_to_string("template_loader/request.html", request=request)
|
||||
self.assertEqual(content, "/foobar/\n")
|
||||
|
||||
def test_render_to_string_using_engine(self):
|
||||
content = render_to_string("template_loader/hello.html", using="django")
|
||||
self.assertEqual(content, "Hello! (Django templates)\n")
|
||||
|
||||
Reference in New Issue
Block a user