Python django.template.context.make_context() Examples
The following are 10
code examples of django.template.context.make_context().
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
django.template.context
, or try the search function
.
Example #1
Source File: test_templatetags.py From wagtail-tag-manager with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_wtm_include_necessary(rf, site): expected_result = '<link href="/static/test.css" rel="stylesheet" type="text/css"/>' token = Token(token_type=TOKEN_TYPE, contents='wtm_include "necessary" "test.css"') parser = Parser(tokens=[token]) node = wtm_include(parser, token) request = rf.get(site.root_page.url) result = node.render(context=make_context({"request": request})) assert result == expected_result request.COOKIES = {"wtm": "necessary:false"} result = node.render(context=make_context({"request": request})) assert result == expected_result request.COOKIES = {"wtm": "necessary:true"} result = node.render(context=make_context({"request": request})) assert result == expected_result
Example #2
Source File: test_templatetags.py From wagtail-tag-manager with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_wtm_include_preferences(rf, site): expected_result = '<script src="/static/test.js" type="text/javascript"></script>' token = Token(token_type=TOKEN_TYPE, contents='wtm_include "preferences" "test.js"') parser = Parser(tokens=[token]) node = wtm_include(parser, token) request = rf.get(site.root_page.url) result = node.render(context=make_context({"request": request})) assert result == expected_result request.COOKIES = {"wtm": "preferences:false"} result = node.render(context=make_context({"request": request})) assert result == "" request.COOKIES = {"wtm": "preferences:true"} result = node.render(context=make_context({"request": request})) assert result == expected_result
Example #3
Source File: django.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def render(self, context=None, request=None): # A deprecation path is required here to cover the following usage: # >>> from django.template import Context # >>> from django.template.loader import get_template # >>> template = get_template('hello.html') # >>> template.render(Context({'name': 'world'})) # In Django 1.7 get_template() returned a django.template.Template. # In Django 1.8 it returns a django.template.backends.django.Template. # In Django 1.10 the isinstance checks should be removed. If passing a # Context or a RequestContext works by accident, it won't be an issue # per se, but it won't be officially supported either. if isinstance(context, RequestContext): if request is not None and request is not context.request: raise ValueError( "render() was called with a RequestContext and a request " "argument which refer to different requests. Make sure " "that the context argument is a dict or at least that " "the two arguments refer to the same request.") warnings.warn( "render() must be called with a dict, not a RequestContext.", RemovedInDjango110Warning, stacklevel=2) elif isinstance(context, Context): warnings.warn( "render() must be called with a dict, not a Context.", RemovedInDjango110Warning, stacklevel=2) else: context = make_context(context, request) return self.template.render(context)
Example #4
Source File: test_templatetags.py From wagtail-tag-manager with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_wtm_include_marketing(rf, site): token = Token(token_type=TOKEN_TYPE, contents='wtm_include "marketing" "test.html"') parser = Parser(tokens=[token]) node = wtm_include(parser, token) with pytest.raises(TemplateDoesNotExist): request = rf.get(site.root_page.url) node.render(context=make_context({"request": request})) request.COOKIES = {"wtm": "marketing:false"} node.render(context=make_context({"request": request})) request.COOKIES = {"wtm": "marketing:true"} node.render(context=make_context({"request": request}))
Example #5
Source File: django.py From bioforum with MIT License | 5 votes |
def render(self, context=None, request=None): context = make_context(context, request, autoescape=self.backend.engine.autoescape) try: return self.template.render(context) except TemplateDoesNotExist as exc: reraise(exc, self.backend)
Example #6
Source File: django.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
def render(self, context=None, request=None): context = make_context(context, request, autoescape=self.backend.engine.autoescape) try: return self.template.render(context) except TemplateDoesNotExist as exc: reraise(exc, self.backend)
Example #7
Source File: django.py From python with Apache License 2.0 | 5 votes |
def render(self, context=None, request=None): context = make_context(context, request, autoescape=self.backend.engine.autoescape) try: return self.template.render(context) except TemplateDoesNotExist as exc: reraise(exc, self.backend)
Example #8
Source File: mail.py From django-templated-mail with MIT License | 5 votes |
def render(self): context = make_context(self.get_context_data(), request=self.request) template = get_template(self.template_name) with context.bind_template(template.template): blocks = self._get_blocks(template.template.nodelist, context) for block_node in blocks.values(): self._process_block(block_node, context) self._attach_body()
Example #9
Source File: django.py From openhgsenti with Apache License 2.0 | 5 votes |
def render(self, context=None, request=None): # A deprecation path is required here to cover the following usage: # >>> from django.template import Context # >>> from django.template.loader import get_template # >>> template = get_template('hello.html') # >>> template.render(Context({'name': 'world'})) # In Django 1.7 get_template() returned a django.template.Template. # In Django 1.8 it returns a django.template.backends.django.Template. # In Django 1.10 the isinstance checks should be removed. If passing a # Context or a RequestContext works by accident, it won't be an issue # per se, but it won't be officially supported either. if isinstance(context, RequestContext): if request is not None and request is not context.request: raise ValueError( "render() was called with a RequestContext and a request " "argument which refer to different requests. Make sure " "that the context argument is a dict or at least that " "the two arguments refer to the same request.") warnings.warn( "render() must be called with a dict, not a RequestContext.", RemovedInDjango110Warning, stacklevel=2) elif isinstance(context, Context): warnings.warn( "render() must be called with a dict, not a Context.", RemovedInDjango110Warning, stacklevel=2) else: context = make_context(context, request) try: return self.template.render(context) except TemplateDoesNotExist as exc: reraise(exc, self.backend)
Example #10
Source File: django.py From python2017 with MIT License | 5 votes |
def render(self, context=None, request=None): context = make_context(context, request, autoescape=self.backend.engine.autoescape) try: return self.template.render(context) except TemplateDoesNotExist as exc: reraise(exc, self.backend)