Skip to content

Commit 3c25e47

Browse files
committed
added jinja quick loa
1 parent 0fb024c commit 3c25e47

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

15_check_my_environment.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ def get_config_file():
4242
print "Config file: {}".format(CONFIGFILE)
4343
if not os.path.exists(CONFIGFILE):
4444
sys.exit("Configuration error! Config file does not exist")
45-
print "Congig ok ...."
45+
print "Config ok ...."

16_jinja_quick_load.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
Render a quick Jinja2 template.
3+
Thanks Danny - http://pydanny.com/jinja2-quick-load-function.html
4+
5+
Example:
6+
7+
>>> from jinja_quick_load import render_from_template
8+
>>> data = {
9+
... "date": "June 12, 2014",
10+
... "items": ["oranges", "bananas", "steak", "milk"]
11+
... }
12+
>>> render_from_template(".", "shopping_list.html", **data)
13+
14+
"""
15+
16+
17+
from jinja2 import FileSystemLoader, Environment
18+
19+
20+
def render_from_template(directory, template_name, **kwargs):
21+
loader = FileSystemLoader(directory)
22+
env = Environment(loader=loader)
23+
template = env.get_template(template_name)
24+
return template.render(**kwargs)

readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
1. **13_random_name_generator.py**: random name generator
1616
1. **14_html_to_markdown.sh**: Convert all html files in a single directory to markdown
1717
1. **15_check_my_environment.py**: Pass in a config file based on your environment.
18+
1. **16_jinja_quick_load.py**: Render a quick Jinja2 template

0 commit comments

Comments
 (0)