Django 6.1.3 on SQLite (in-memory): ch10-presentation 1. Lexer.tokenize and Parser.parse over desk edition.html edition.html: chars=904 tokens=48 counts=TEXT:22,VAR:9,BLOCK:17 first_8_tokens: L01 BLOCK 'extends "newsroom/base.html"' L01 TEXT '\\n' L02 BLOCK 'block title' L02 BLOCK 'if edition' L02 VAR 'edition.title' L02 TEXT ' — ' L02 VAR 'edition.slug' L02 BLOCK 'else' top_nodelist = ['ExtendsNode'] extends_parent='"newsroom/base.html"' blocks=['title', 'content'] if_nodes=3 for_nodes=1 for_loop_children=11 for_empty_children=1 2. Context stack, BlockContext, and shared-Node vs RenderContext Context.dicts depth: initial=2 pushed=3 popped=2 inside='Metro Desk' after='Front Page' shared_Node_bug (2 renders): buggy=['1', '2'] render_context_safe=['12', '12'] edition.html rendered: chars=1213 has_title=True stories_rendered=4 3. Cached template loader and conditional_escape cached_loader: t1_is_t2=True cache_keys=['newsroom/edition.html'] autoescape_plain = '<script>alert("x")</script>' autoescape_safe = 'Breaking' autoescape_off = '' conditional_escape(plain)='<script>alert("x")</script>' conditional_escape(safe)='Breaking' 4. Form metaclass, field deep-copying, and BoundField on StoryForm StoryForm.base_fields = ['headline', 'slug', 'desk', 'reporter', 'edition', 'priority', 'body'] per_instance_deepcopy: f1_is_base=False field_obj_shared=False BoundField('headline', prefix='draft'): html_name='draft-headline' auto_id='id_draft-headline' widget=TextInput cached=True widget_html = '' 5. Three-stage full_clean pipeline on StoryForm invalid_submit: is_valid=False headline_in_cleaned_data=False cleaned_keys=['body', 'desk', 'edition', 'priority', 'reporter', 'slug'] error_dict = {'headline': [{'message': 'Use sentence case, not all-caps headlines.', 'code': ''}], '__all__': [{'message': 'Cora files for City Hall, not Metro.', 'code': ''}]} valid_submit: is_valid=True errors={} cleaned_headline='Council approves ferry dock' 6. ModelForm._post_clean instance mutation trap and save(commit=False) unique_fail: is_valid=False errors=['slug'] instance_mutated_despite_invalid: before='Bridge bond passes council' after_is_valid='Mutated Headline In Memory' db_still='Bridge bond passes council' save(commit=False): pk=None adding=True has_save_m2m_before=False has_save_m2m_after=True 7. BaseFormSet, ManagementForm tampering, and BaseInlineFormSet inline_unbound: prefix='corrections' initial=2 total=3 max_num=1000 absolute_max=2000 form_prefixes = ['corrections-0', 'corrections-1', 'corrections-2'] extra_empty_permitted=True missing_mgmt: is_valid=False total_forms=0 non_form_errors=['ManagementForm data is missing or has been tampered with. Missing fields: corrections-TOTAL_FORMS, corrections-INITIAL_FORMS. You may need to file a bug report if the issue persists.'] valid_inline_post: is_valid=True changed_forms=['corrections-0'] extra_form_cleaned_empty=True