I'm always excited to take on new projects and collaborate with innovative minds.
+855 12 282 686
samnangrosady9@gmail.com
Jinja: template engine

🧙♂️ Jinja is a modern and designer-friendly templating language for Python, used to generate files dynamically. Think of it like Mad Libs for config files, where you can inject variables into a template and programmatically generate output.
It’s used heavily in:
Use Jinja when you want to:
| When... | Why |
|---|---|
| You only need one or two static files | Overkill. Just use Vim and be done. |
| You need real-time updates (e.g. hot reload UIs) | Jinja is static. It renders once and that's it. |
| Your team has zero Python experience | Might be a steep ramp-up. |
| You want complex business logic in templates | Templates are not codebases! 🤯 |
Let’s break it down with an imaginative metaphor:
"Using
vimfor 1,000 NGINX config files is like writing wedding invitations by hand. Sweet, but painful." Jinja is like a laser printer with your best handwriting.
Scenario: You run a massive fleet of servers and each one needs its own NGINX configuration:
→ vim
→ Modify
→ Save
→ Repeat 999 times 🔁
→ Cry 😭

You write one template:
# nginx_template.j2
upstream {{ upstream }} {
{% for upstream_item in upstream_servers%}
{{- upstream_item }};
{% endfor %}
}
server {
listen 80;
server_name {{ domain_name }};
rewrite ^(.*) https://$host$1 permanent;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name {{ domain_name }};
server_tokens off;
ssl_certificate /etc/letsencrypt/live/{{ domain_name }}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/{{ domain_name }}/privkey.pem;
client_max_body_size 50M;
access_log /var/log/nginx/{{ domain_name }}-access.log;
error_log /var/log/nginx/{{ domain_name }}-error.log;
{%- if auth %}
auth_basic {{ auth.auth_basic }};
auth_basic_user_file {{ auth.auth_user_file }};
{% endif -%}
location / {
access_log /var/log/nginx/{{ domain_name }}-access.log;
proxy_pass {{ upstream }};
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
}
}
With dynamic data with json
app.local.json
{
"domain_name" : "app.local",
"upstream" : "http://proxy-app",
"upstream_servers" : [
"server 10.143.41.104:8081",
"server 10.143.41.104:8082",
"server 10.143.41.104:8083"
],
"auth" : {
"auth_basic" : "Restricted Area",
"auth_user_file" : "/etc/nginx/htpasswd/auth"
}
}
Run-time 🏃
jinja2 ./nginx_template.j2 ./app.local.json --format=json --outfile=./app.local.conf
Now you’ve got a thousand configs generated faster than a barista can spell your name wrong.
Jinja is the unsung hero of DevOps, backend automation, and lazy (smart) developers everywhere. It’s not flashy, but it’s reliable, fast, and scales beautifully. 🚀
Use it wisely — and maybe, just maybe, save your fingers from vim-induced arthritis.