Skip to main content

django-typescript-routes

Meant as a spiritual successor to django-js-reverse, django-typescript-routes is meant to answer to the following question:

I've got a Typescript-based SPA that is powered by a Django-based API. How do I safely make requests to Django without messing up the routes or parameters?

django-typescript-routes is how! At a high level, it turns:

urls = [
    path(
        r"about",
        about,
        name="about",
    ),
    path(
        r"/<str:username>",
        subscribe,
        name="subscribe",
    ),
    path(
        r"/<str:username>/subscribers/<pk:uuid>/success",
        subscription_success,
        name="subscription-success",
    ),
]

into:

const URLS = {
  about: () => `/`,
  subscribe: (username: string) => `/${username}`,
  "subscription-success": (username: string, pk: string) =>
    `/${username}/subscribers/${pk}/success`,
};

Quick start

  1. Install:
uv add django-typescript-routes
  1. Add django-typescript-routes to your INSTALLED_APPS setting:
INSTALLED_APPS = [
    ...,
    "typescript_routes",
    ...
]
  1. Run the management command to print out the typescript file:
python manage.py generate_typescript_routes --urlconf projectname.urls > assets/urls.ts

Contributing

Running the test suite

Simply:

./scripts/test

Release files for django-typescript-routes 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-typescript-routes 0.4.0
File Size Uploaded
django_typescript_routes-0.4.0.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-typescript-routes 0.4.0
File Interpreter ABI Platform
django_typescript_routes-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.8 kB

Release files / django_typescript_routes-0.4.0.tar.gz

Download URL django_typescript_routes-0.4.0.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
db66b123289e4baf6aa689bf4e3bbacf595a5b933e00d5246f8876e189419b89
BLAKE2b-256 checksum
How to use checksums
ff9eb42fbcff435698ab3daafb89cc8d8f56a1c40dfd4534c9961ab7091b73af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.3

Release files / django_typescript_routes-0.4.0-py3-none-any.whl

Download URL django_typescript_routes-0.4.0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5c3a34ea3122076969f3415772f52bce423b67e976b9cbf10d5627f349e75673
BLAKE2b-256 checksum
How to use checksums
d1f0f5f6b5daa419fdd1677161e7d9fe5032e506e5320acdbd2038812b146c2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.3

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page