<s> from __future__ import absolute_import , unicode_literals <EOL> from django . http import HttpResponseBadRequest <EOL> from django . shortcuts import render_to_response <EOL> from django . template import TemplateDoesNotExist <EOL> from django . utils . safestring import mark_safe <EOL> from debug_toolbar . compat import get_template_loaders <EOL> def template_source ( request ) : <EOL> """<STR_LIT>""" <EOL> template_name = request . GET . get ( '<STR_LIT>' , None ) <EOL> if template_name is None : <EOL> return HttpResponseBadRequest ( '<STR_LIT>' ) <EOL> final_loaders = [ ] <EOL> loaders = get_template_loaders ( ) <EOL> for loader in loaders : <EOL> if loader is not None : <EOL> if hasattr ( loader , '<STR_LIT>' ) : <EOL> final_loaders += loader . loaders <EOL> else : <EOL> final_loaders . append ( loader ) <EOL> for loader in final_loaders : <EOL> try : <EOL> source , display_name = loader . load_template_source ( template_name ) <EOL> break <EOL> except TemplateDoesNotExist : <EOL> source = "<STR_LIT>" % ( template_name , ) <EOL> try : <EOL> from pygments import highlight <EOL> from pygments . lexers import HtmlDjangoLexer <EOL> from pygments . formatters import HtmlFormatter <EOL> source = highlight ( source , HtmlDjangoLexer ( ) , HtmlFormatter ( ) ) <EOL> source = mark_safe ( source ) <EOL> source . pygmentized = True <EOL> except ImportError : <EOL> pass <EOL> return render_to_response ( '<STR_LIT>' , { <EOL> '<STR_LIT:source>' : source , <EOL> '<STR_LIT>' : template_name <EOL> } ) </s>
