Skip to main content

a python package for type checking the urls and associated views.

Project description

Django UrlConf Checks

django-urlconfchecks logo

pypi python Build Status codecov License

Static checker that keeps your URL patterns and view annotations in sync, using Django’s built-in check framework.

Key features

  • Detects mismatches between URL converters/default kwargs and view annotations (ints, UUIDs, container generics, etc.).
  • Works as a Django system check (manage.py check) or standalone CLI.
  • Honors custom converters and fine-grained silencing per view.
  • Pre-commit friendly; CI-ready with machine-readable output.

Installation

pip install django-urlconfchecks

Compatibility:

Python Django
3.10–3.11 5.2.8 – <5.3
3.12–3.14 5.2.8 – <6.1

Quick start

  1. Install: pip install django-urlconfchecks

  2. From your project root (where manage.py lives): urlconfchecks

    • Or target a specific module: urlconfchecks --urlconf myproj.urls
  3. Optional: add defaults in pyproject.toml:

    [tool.urlconfchecks]
    quiet = true
    format = "json"
    silenced_views = { "myproj.views.legacy_view" = "E002" }
    

    CLI flags always override these defaults.

Usage

As a Django app

Add django_urlconfchecks to your INSTALLED_APPS list in your settings.py file.

    INSTALLED_APPS = [
    ...
    'django_urlconfchecks',
]

As a command line tool

Run this command from the root of your project, were manage.py is located:

$ urlconfchecks --help

    Usage: urlconfchecks [OPTIONS]

      Check all URLConfs for errors.

    Options:
      --version
      -u, --urlconf PATH    Specify the URLconf to check.
      -q, --quiet           Suppress human-readable output; exit codes still set.
      -f, --format TEXT     Output format. Supported: json.
      --install-completion  Install completion for the current shell.
      --show-completion     Show completion for the current shell, to copy it or
                            customize the installation.
      --help                Show this message and exit.

As a pre-commit hook

Add the following to your .pre-commit-config.yaml file:

  - repo: https://github.com/AliSayyah/django-urlconfchecks
    rev: v0.13.2
    hooks:
      - id: django-urlconfchecks

For more information, see the usage documentation.

What it catches (example)

# urls.py
from django.urls import path

from . import views

urlpatterns = [
    path('articles/<str:year>/', views.year_archive),
    path('articles/<int:year>/<int:month>/', views.month_archive),
    path('articles/<int:year>/<int:month>/<slug:slug>/', views.article_detail),
]
# views.py

def year_archive(request, year: int):
    pass


def month_archive(request, year: int, month: int):
    pass


def article_detail(request, year: int, month: int, slug: str):
    pass

Output:

(urlchecker.E002) For parameter `year`, annotated type int does not match expected `str` from urlconf

JSON (--format json):

{
  "errors": [
    {
      "id": "urlchecker.E002",
      "message": "View myproj.views.year_archive for parameter `year`, annotated type int does not match expected `str` from urlconf",
      "obj": "<URLPattern 'articles/<str:year>/'>",
      "hint": null
    }
  ],
  "warnings": [],
  "total_errors": 1,
  "total_warnings": 0
}

Credits

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_urlconfchecks-0.13.2.tar.gz (45.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_urlconfchecks-0.13.2-py3-none-any.whl (37.5 kB view details)

Uploaded Python 3

File details

Details for the file django_urlconfchecks-0.13.2.tar.gz.

File metadata

  • Download URL: django_urlconfchecks-0.13.2.tar.gz
  • Upload date:
  • Size: 45.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_urlconfchecks-0.13.2.tar.gz
Algorithm Hash digest
SHA256 4efa62580bf5786ac65a61cb5849cd9ec484dca7795cb7aca70a67136bb0b18e
MD5 ef5523ce7208c34bf9b3f0fe2014b9a5
BLAKE2b-256 ef184031e9b0724d781e4a9bf744ba04d80019eddb51daa54f1c7d8e06fb89e1

See more details on using hashes here.

File details

Details for the file django_urlconfchecks-0.13.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_urlconfchecks-0.13.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4d0181489feeb387a28271b29f4f325bb6e64055d6aa16fd285d3f0e2068c84b
MD5 74b3228e5be81ffd60a9bf8447c2567d
BLAKE2b-256 cb6da50c3cfc935f08ec6c92d99066a1b3fbe3e5724ceb20ba2d5c0967b62325

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page