Golang html/template versus Python Jinja2 (2)
source link: http://siongui.github.io/2015/02/24/python-jinja2-vs-go-html-template-2/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Golang html/template versus Python Jinja2 (2)
February 24, 2015
Print Hello World! on screen by Python Jinja2 and Go html/template respectively.
Python Jinja2:
jinja2-example-1.py | repository | view raw
#!/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
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
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK