Skip to content

Link check reports correct links for a Django app whose sub-path comes from the server #465

Open

Description

@JuroOravec

What happens

citry.template.unknown-url reports correct links as missing when a Django app is served below a sub-path that only the server sets, through the WSGI or ASGI SCRIPT_NAME, and FORCE_SCRIPT_NAME is not set.

For example, the app runs under /shop, behind gunicorn with SCRIPT_NAME=/shop, and a template has <a href="/shop/cart">. Django serves that link, but the check reports it.

Why

The Django path checker in packages/py/citry/citry/contrib/django.py (the check() function returned for urlpatterns()) removes the sub-path using get_script_prefix(). Outside a request, that prefix comes only from FORCE_SCRIPT_NAME, which django.setup() applies. A sub-path from the server is set per request, so citry check and the editor see /. They then compare /shop/cart with the URL patterns as if it were served at the site root, and nothing matches.

The same thing happens with FastAPI's root_path and Flask's APPLICATION_ROOT (contrib/fastapi.py:104, contrib/flask.py:173), where the checker always compares against the site root.

Current workaround

Documented in #464 under "Unexpected link results": set FORCE_SCRIPT_NAME to the same sub-path, or set rule_unknown_url to "ignore" for that app.

Possible fix

Give the app a way to tell the check its sub-path. That could be a Citry setting, or reading it from the env file, or a parameter to urlpatterns() and mount(). The checker would then remove the sub-path before it asks the framework, for all three integrations. Whatever is chosen, it should say what happens with an empty value, a value with no leading /, or a value with a trailing /.

🤖 Generated with Claude Code

Activity

  1. added
    next-sprint
    on Oct 28, 2026
  2. JuroOravec commented on Oct 28, 2026

    @JuroOravec
    MemberAuthor

    Decision (Juro): the rest of this issue, a sub-path that only the server sets (gunicorn's SCRIPT_NAME, uvicorn's --root-path), gets option (a), a Citry setting that tells the link check the sub-path. It is scheduled after 0.7.0. #472 covers the part that reads each framework's own setting (FastAPI root_path, Flask APPLICATION_ROOT, Django FORCE_SCRIPT_NAME).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    next-sprint

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions