Skip to main content

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

Project description

Django UrlConf Checks

pypi python Build Status codecov License

a python package for type checking the urls and associated views

Installation

pip install django-urlconfchecks

Usage

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

INSTALLED_APPS = [
    ...
    'django_urlconfchecks',
]

Features

Using this package, URL pattern types will automatically be matched with associated views, and in case of mismatch, an error will be raised.

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 special_case(request):
    pass


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 will be:

(urlchecker.E002) For parameter `year`, annotated type int does not match expected `str` from urlconf
  • TODO
    • Fine-grained methods for silencing checks.
    • Should only warn for each unhandled Converter once
    • Regex patterns perhaps? (only RoutePattern supported at the moment)

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.4.0.tar.gz (20.4 kB view hashes)

Uploaded Source

Built Distribution

django_urlconfchecks-0.4.0-py3-none-any.whl (17.5 kB view hashes)

Uploaded Python 3

Supported by

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