Django blocks: extend, inherit, replace
HTML for this example
Select the code and use your copy shortcut. Changes in this preview are temporary.
<!doctype html><html lang="en-US"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Django blocks: extend, inherit, replace</title><style>*{box-sizing:border-box}:root{--ink:#24333d;--muted:#586872;--line:#cfd9de;--accent:#27627b;--soft:#edf3f5;--paper:white;color-scheme:light}body{margin:0;background:#f2f4f4;color:var(--ink);font:16px/1.5 system-ui,-apple-system,"Segoe UI",sans-serif}main{max-width:1100px;padding:28px 32px 64px;margin:auto}header{margin-bottom:20px}h1{font-size:clamp(1.5rem,3vw,2.1rem);letter-spacing:-.035em;line-height:1.18;margin:0 0 9px}h2{font-size:1.2rem;line-height:1.3;margin:0 0 15px}h3{font-size:1rem;margin:0 0 8px}p{margin:9px 0 16px}header p{margin-bottom:0}.eyebrow{font-size:.75rem;font-weight:750;text-transform:uppercase;letter-spacing:.12em;color:var(--accent);margin-bottom:8px}.muted,small{color:var(--muted)}.panel{background:var(--paper);border:1px solid var(--line);padding:24px;border-radius:12px}.grid{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:24px}.fields{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:15px}.triple{display:grid;grid-template-columns:2fr 1fr 1fr;gap:16px}.below{margin-top:24px}label{display:block;font-size:.9rem;font-weight:650}input,select,textarea,button{font:inherit}input,select,textarea{display:block;width:100%;min-width:0;margin-top:6px;padding:10px 12px;border:1px solid #879da8;border-radius:6px;background:white;color:var(--ink)}input,select{min-height:46px}textarea{resize:vertical;line-height:1.6}button{min-height:44px;border:1px solid var(--accent);border-radius:6px;padding:9px 15px;background:var(--accent);color:white;font-weight:650;cursor:pointer}button.secondary{background:white;color:var(--accent)}button:disabled{opacity:.5;cursor:not-allowed}button:hover:enabled{filter:brightness(.95)}:focus-visible{outline:3px solid #bb6b22;outline-offset:3px}.actions{display:flex;flex-wrap:wrap;gap:10px;margin-top:18px}.result{padding:26px;background:var(--ink);color:white;border-radius:12px}.result .muted{color:#d1e0e7}.big{font-size:clamp(2rem,5vw,3.5rem);line-height:1.15;letter-spacing:-.04em;font-weight:750;font-variant-numeric:tabular-nums;margin:10px 0;overflow-wrap:anywhere}.formula{font-family:ui-monospace,SFMono-Regular,Consolas,monospace;overflow-wrap:anywhere}.error{min-height:24px;color:#a33028;font-weight:650;margin:9px 0 0}.status{font-size:.9rem;color:var(--muted)}.note{padding:12px 16px;background:#fff3de;border-left:3px solid #b67e38;color:#65481d}table{width:100%;border-collapse:collapse;font-size:.92rem}th{text-align:left;color:var(--muted);font-size:.83rem}th,td{padding:10px 8px;border-bottom:1px solid var(--line);vertical-align:top}th:first-child,td:first-child{padding-left:0}details{padding:16px 0;border-top:1px solid var(--line)}summary{font-weight:650;cursor:pointer}pre{white-space:pre-wrap;overflow-wrap:anywhere;font:.87rem/1.6 ui-monospace,Consolas,monospace;background:#edf1f3;border:1px solid #d7e0e4;padding:18px;border-radius:7px}svg{display:block;width:100%;height:auto}.badge{display:inline-block;padding:3px 9px;background:var(--soft);color:var(--accent);font-size:.78rem;font-weight:700;border-radius:25px}.rule{height:1px;background:var(--line);margin:18px 0}[hidden]{display:none!important}a{color:var(--accent)}@media(max-width:720px){main{padding:22px 20px 45px}.grid{grid-template-columns:1fr;gap:18px}.panel{padding:20px}.triple{grid-template-columns:1fr 1fr}.triple>label:first-child{grid-column:1/-1}}@media(max-width:400px){main{padding:18px 16px 36px}.panel{padding:16px}.fields{gap:12px}.result{padding:20px}.big{font-size:2.2rem}th,td{padding:9px 5px}}:root{--accent:#3f6a58}body{background:#eef2ef}.block-result{background:white;border:1px solid #bdcfc4;border-top:5px solid #5f8a73;padding:24px}.result-label{font-size:.78rem;letter-spacing:.08em;text-transform:uppercase;color:#5c7567}.preview-title{font-size:1.8rem;font-weight:700;margin:12px 0}.block-result footer{border-top:1px solid #cfdbd4;margin-top:18px;padding-top:12px;color:#607265}.block-result p{margin:8px 0}pre{margin:0;min-height:275px;background:#1e3130;color:#e2efeb;border:0}#childSource{border-top:4px solid #a4bca9}@media(max-width:720px){pre{min-height:0;font-size:.82rem}}</style></head><body><main><header><h1>Django blocks: extend, inherit, replace</h1><p>A reference model of three authored cases; this page does not run Django.</p></header>
<section class="block-result"><div class="result-label">Expected document · selected case</div><div class="preview-title" id="previewTitle">Practice</div><div id="previewBody"><p>Shared checklist.</p><p>Confirm the supplied inputs.</p></div><footer id="previewFooter">Demo only.</footer></section>
<section class="panel below"><label for="case">Child body behavior<select id="case"><option value="extend">Extend with block.super</option><option value="omit">Omit the body block</option><option value="replace">Replace without block.super</option></select></label><p id="mapping" class="status" aria-live="polite"></p></section>
<div class="grid below"><section><h2>base.html · parent owns the shell</h2><pre id="parentSource"><!doctype html>
<html lang="en">
<head><title>{% block title %}Notes{% endblock %}</title></head>
<body>
<main>{% block body %}<p>Shared checklist.</p>{% endblock %}</main>
<footer>Demo only.</footer>
</body>
</html></pre></section><section><h2>child.html · selected source</h2><pre id="childSource"></pre></section></div>
<section class="panel below"><h2>Expected order and count</h2><p id="counts" class="formula"></p><p>Title and body use matching named blocks. The footer sits outside the body block, so it survives all three cases. The child contains no second document shell or footer.</p></section>
<details class="below"><summary>Native render record · not executed</summary><table><tr><th>Field</th><th>Status</th></tr><tr><td>Documentation reference</td><td>Django 5.2 selected; not a latest-version claim</td></tr><tr><td>Actual installed engine / version</td><td>Not recorded</td></tr><tr><td>Actual loader location / settings</td><td>Not recorded</td></tr><tr><td>Observed engine output / bytes</td><td>Not run</td></tr></table><p>Use the native templates in a configured Django environment for actual output. If the parent cannot be loaded, record that real loader error. A misspelled block needs a source comparison, not a copied parent paragraph. Changed sources require new engine evidence.</p><p>block.super reuses parent-rendered content; it does not make arbitrary external HTML trusted. These fixed original strings use no safe filter or autoescape-off shortcut.</p></details></main><script>const $=id=>document.getElementById(id),put=(id,s)=>{$(id).textContent=s};
function esc(s){return String(s).replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));}
function gcd(a,b){a=a<0n?-a:a;b=b<0n?-b:b;while(b){[a,b]=[b,a%b]}return a||1n;}
function R(n,d=1n){n=BigInt(n);d=BigInt(d);if(d===0n)throw Error('Undefined denominator.');if(d<0n){n=-n;d=-d}const g=gcd(n,d);return {n:n/g,d:d/g};}
function mul(a,b){return R(a.n*b.n,a.d*b.d)}function div(a,b){return R(a.n*b.d,a.d*b.n)}function add(a,b){return R(a.n*b.d+b.n*a.d,a.d*b.d)}function sub(a,b){return R(a.n*b.d-b.n*a.d,a.d*b.d)}function cmp(a,b){const x=a.n*b.d-b.n*a.d;return x<0n?-1:x>0n?1:0}
function parse(s,{max=1000000,positive=false,places=6}={}){const t=String(s).trim();if(!t)throw Error('Enter a value; blank is not zero.');const re=new RegExp('^[0-9]+(?:\.[0-9]{1,'+places+'})?$');if(!re.test(t))throw Error('Use digits and a US decimal point, up to '+places+' places; no signs, commas, or exponents.');const v=Number(t);if(!Number.isFinite(v)||v>max||(positive&&v===0))throw Error('Value must be '+(positive?'greater than zero':'nonnegative')+' and at most '+max+'.');const [a,b='']=t.split('.');return R(BigInt(a+b),10n**BigInt(b.length));}
function format(a,places=6){const neg=a.n<0n,n=neg?-a.n:a.n,scale=10n**BigInt(places),v=n*scale,q=v/a.d,rem=v%a.d,k=q+(rem*2n>=a.d?1n:0n);const f=(k%scale).toString().padStart(places,'0').replace(/0+$/,'');return {text:(neg&&k!==0n?'-':'')+(k/scale)+(f?'.'+f:''),approx:rem!==0n};}
function exact(a){let d=a.d;while(d%2n===0n)d/=2n;while(d%5n===0n)d/=5n;if(d!==1n)return a.n+'/'+a.d;let places=0,p=1n;while(p%a.d!==0n&&places<40){p*=10n;places++}return format(a,places).text;}
function display(a,places=6){if(a.n>0n&&cmp(a,R(1n,10n**BigInt(places)))<0)return '< '+format(R(1n,10n**BigInt(places)),places).text;const f=format(a,places);return (f.approx?'≈ ':'')+f.text;}
function listen(ids,fn){ids.forEach(id=>{ $(id).addEventListener('input',fn);$(id).addEventListener('change',fn); });}
const childCases={"extend":"{% extends \"base.html\" %}\n{% block title %}Practice{% endblock %}\n{% block body %}\n{{ block.super }}\n<p>Confirm the supplied inputs.</p>\n{% endblock %}","omit":"{% extends \"base.html\" %}\n{% block title %}Practice{% endblock %}","replace":"{% extends \"base.html\" %}\n{% block title %}Practice{% endblock %}\n{% block body %}<p>Confirm the supplied inputs.</p>{% endblock %}"};
function expectedCase(name){if(!Object.hasOwn(childCases,name))throw Error('Unsupported authored case.');const shared=name!=='replace',added=name!=='omit';return {title:'Practice',body:[...(shared?['Shared checklist.']:[]),...(added?['Confirm the supplied inputs.']:[])],footer:'Demo only.',source:childCases[name],shared,added};}
function update(){const r=expectedCase($('case').value);put('previewTitle',r.title);$('previewBody').innerHTML=r.body.map(s=>'<p>'+esc(s)+'</p>').join('');put('previewFooter',r.footer);put('childSource',r.source);put('mapping',$('case').value==='extend'?'body → parent content, then child addition. title → child. footer → parent.':$('case').value==='omit'?'body → parent default. title → child. footer → parent.':'body → child replacement only. title → child. footer → parent.');put('counts','Expected: Shared checklist. × '+(r.shared?1:0)+'; Confirm the supplied inputs. × '+(r.added?1:0)+'; Demo only. × 1.');}
$('case').addEventListener('change',update);globalThis.Tool={expectedCase,update};update();</script></body></html>