测试gitnore
This commit is contained in:
@@ -12,25 +12,24 @@ from .base import BaseEngine
|
||||
|
||||
class Jinja2(BaseEngine):
|
||||
|
||||
app_dirname = "jinja2"
|
||||
app_dirname = 'jinja2'
|
||||
|
||||
def __init__(self, params):
|
||||
params = params.copy()
|
||||
options = params.pop("OPTIONS").copy()
|
||||
options = params.pop('OPTIONS').copy()
|
||||
super().__init__(params)
|
||||
|
||||
self.context_processors = options.pop("context_processors", [])
|
||||
self.context_processors = options.pop('context_processors', [])
|
||||
|
||||
environment = options.pop("environment", "jinja2.Environment")
|
||||
environment = options.pop('environment', 'jinja2.Environment')
|
||||
environment_cls = import_string(environment)
|
||||
|
||||
if "loader" not in options:
|
||||
options["loader"] = jinja2.FileSystemLoader(self.template_dirs)
|
||||
options.setdefault("autoescape", True)
|
||||
options.setdefault("auto_reload", settings.DEBUG)
|
||||
options.setdefault(
|
||||
"undefined", jinja2.DebugUndefined if settings.DEBUG else jinja2.Undefined
|
||||
)
|
||||
if 'loader' not in options:
|
||||
options['loader'] = jinja2.FileSystemLoader(self.template_dirs)
|
||||
options.setdefault('autoescape', True)
|
||||
options.setdefault('auto_reload', settings.DEBUG)
|
||||
options.setdefault('undefined',
|
||||
jinja2.DebugUndefined if settings.DEBUG else jinja2.Undefined)
|
||||
|
||||
self.env = environment_cls(**options)
|
||||
|
||||
@@ -53,23 +52,22 @@ class Jinja2(BaseEngine):
|
||||
|
||||
|
||||
class Template:
|
||||
|
||||
def __init__(self, template, backend):
|
||||
self.template = template
|
||||
self.backend = backend
|
||||
self.origin = Origin(
|
||||
name=template.filename,
|
||||
template_name=template.name,
|
||||
name=template.filename, template_name=template.name,
|
||||
)
|
||||
|
||||
def render(self, context=None, request=None):
|
||||
from .utils import csrf_input_lazy, csrf_token_lazy
|
||||
|
||||
if context is None:
|
||||
context = {}
|
||||
if request is not None:
|
||||
context["request"] = request
|
||||
context["csrf_input"] = csrf_input_lazy(request)
|
||||
context["csrf_token"] = csrf_token_lazy(request)
|
||||
context['request'] = request
|
||||
context['csrf_input'] = csrf_input_lazy(request)
|
||||
context['csrf_token'] = csrf_token_lazy(request)
|
||||
for context_processor in self.backend.template_context_processors:
|
||||
context.update(context_processor(request))
|
||||
try:
|
||||
@@ -85,7 +83,6 @@ class Origin:
|
||||
A container to hold debug information as described in the template API
|
||||
documentation.
|
||||
"""
|
||||
|
||||
def __init__(self, name, template_name):
|
||||
self.name = name
|
||||
self.template_name = template_name
|
||||
@@ -102,27 +99,27 @@ def get_exception_info(exception):
|
||||
if source is None:
|
||||
exception_file = Path(exception.filename)
|
||||
if exception_file.exists():
|
||||
with open(exception_file, "r") as fp:
|
||||
with open(exception_file, 'r') as fp:
|
||||
source = fp.read()
|
||||
if source is not None:
|
||||
lines = list(enumerate(source.strip().split("\n"), start=1))
|
||||
lines = list(enumerate(source.strip().split('\n'), start=1))
|
||||
during = lines[lineno - 1][1]
|
||||
total = len(lines)
|
||||
top = max(0, lineno - context_lines - 1)
|
||||
bottom = min(total, lineno + context_lines)
|
||||
else:
|
||||
during = ""
|
||||
during = ''
|
||||
lines = []
|
||||
total = top = bottom = 0
|
||||
return {
|
||||
"name": exception.filename,
|
||||
"message": exception.message,
|
||||
"source_lines": lines[top:bottom],
|
||||
"line": lineno,
|
||||
"before": "",
|
||||
"during": during,
|
||||
"after": "",
|
||||
"total": total,
|
||||
"top": top,
|
||||
"bottom": bottom,
|
||||
'name': exception.filename,
|
||||
'message': exception.message,
|
||||
'source_lines': lines[top:bottom],
|
||||
'line': lineno,
|
||||
'before': '',
|
||||
'during': during,
|
||||
'after': '',
|
||||
'total': total,
|
||||
'top': top,
|
||||
'bottom': bottom,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user