【发布时间】:2015-04-28 23:26:21
【问题描述】:
我正在为我的代码编写一个 django 模板。代码的输出是 100 行的运行日志,所有行都以时间戳开头。 如何编写一个模板,以红色突出显示包含字符串“host to”的所有行? 谢谢!!
视图是:
def runlog(request):
path = request.GET.get('FolderPath')
chapter_number = request.GET.get('chapter_number')
content = {'chapter_number': chapter_number}
title = 'Runlog'
content = Test(content, path)
return render_to_response('myproject/src/sourcefile.html', {'content': content, 'title': title}, context_instance=RequestContext(request))
输出是:
13:46:20: open file file1.TXT
13:46:20: file: run 1
13:46:20: host to A: Deactivate 0
13:46:22: host to A: 0 24 -1 0 0
13:46:22: A to host: Return=0
##################################
【问题讨论】:
-
这是一个非常广泛的问题。您可以编写自定义模板过滤器或编写一些客户端 (JavaScript) 代码。
-
谢谢!我想我将不得不使用自定义模板
-
Test(content, path)返回什么? -
另外,添加模板代码,而不是渲染模板的代码。
-
Test(content, path) 返回数百行的运行日志。
标签: django templates django-templates highlight