Golang html/template versus Python Jinja2 (2)


Print Hello World! on screen by Python Jinja2 and Go html/template respectively.

Python Jinja2:

jinja2-example-1.py | repository | view raw
1
2
3
4
5
6
7
8
9
#!/usr/bin/env python
# -*- coding:utf-8 -*-

from jinja2 import Template
import sys

if __name__ == '__main__':
  tmpl = Template("Hello {{ name }}!")
  sys.stdout.write(tmpl.render(name="World"))

Go html/template:

html-template-example-1.go | repository | view raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
package main

import (
	"html/template"
	"os"
)

func main() {
	t, _ := template.New("foo").Parse(`Hello {{.}}!`)
	t.Execute(os.Stdout, "World")
}

Tested on: Ubuntu Linux 14.10, Go 1.4, Python 2.7.8, Jinja2 2.7.3


Golang html/template versus Python Jinja2 series:

[1]Golang html/template versus Python Jinja2 (1)
[2]Golang html/template versus Python Jinja2 (2)
[3]Golang html/template versus Python Jinja2 (3) - Arrays and Slices
[4]Golang html/template versus Python Jinja2 (4) - Arrays and Slices Index
[5]Golang html/template versus Python Jinja2 (5) - Maps and Dictionaries
[6]Golang html/template versus Python Jinja2 (6) - Template Inheritance (Extends)
[7]Golang html/template versus Python Jinja2 (7) - Custom Functions and Filters