Reduce duplicated code by using jinja2 template