Personal Catalogue: Django & PostgreSQL — Chapter 10, Exercise 1 ==================================================== TASK Write the nginx `location /catalogue/` block from this chapter, set FORCE_SCRIPT_NAME=/catalogue in a local test .env, and confirm a rendered {% url 'item_detail' item.pk %} link now correctly includes the /catalogue prefix. SOLUTION 1. nginx location block (added inside the existing server block that already serves the Astro site): location /catalogue/ { proxy_pass http://127.0.0.1:8000/; 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; } 2. In a local test .env: FORCE_SCRIPT_NAME=/catalogue 3. In settings.py (already present from Chapter 9's own env-based settings pattern): FORCE_SCRIPT_NAME = config('FORCE_SCRIPT_NAME', default=None) 4. Restart the local Gunicorn process so the new setting is picked up, then render a template containing: {{ item.title }} EXPECTED RESULT With FORCE_SCRIPT_NAME unset (the normal local-dev case), the rendered link is: /item/1/ With FORCE_SCRIPT_NAME=/catalogue set, the identical template tag now renders: /catalogue/item/1/ with zero changes made to the template itself. WHY THIS HAPPENS Django's {% url %} tag and reverse() both build a URL starting from what Django itself believes is the application's own root path. By default that root is "/". FORCE_SCRIPT_NAME overrides that internal assumption for the whole application at once, so every URL Django generates - not just this one link - picks up the prefix automatically. ANSWER: with FORCE_SCRIPT_NAME=/catalogue set, {% url 'item_detail' item.pk %} renders /catalogue/item/1/ instead of /item/1/, with no template changes required, confirming the setting works at the framework level rather than per-template. WHY THIS WORKS AS AN ANSWER ---------------------------- It reproduces the real nginx config and Django setting from the chapter, then demonstrates the actual before/after rendered output rather than just asserting the setting "should" work.