Generate typescript routes from a Django URLconf
Project description
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
- Install:
uv add django-typescript-routes
- Add
django-typescript-routesto yourINSTALLED_APPSsetting:
INSTALLED_APPS = [
...,
"typescript_routes",
...
]
- 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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_typescript_routes-0.3.0.tar.gz.
File metadata
- Download URL: django_typescript_routes-0.3.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2c10b6d84407bc9254215514936d23afff33358cc477ade8c5bcdaf96a39608
|
|
| MD5 |
a2f1a58fc1e6253868abd4c289bc2ac6
|
|
| BLAKE2b-256 |
8a247c3d649a50aa92e3bf33890bd140d5fc90aa04d7c3f7b963c8e44d9fbb8d
|
File details
Details for the file django_typescript_routes-0.3.0-py3-none-any.whl.
File metadata
- Download URL: django_typescript_routes-0.3.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8ac8833587d2defe303207d67a008d65ab606a273124f64e5b645aa2deef103
|
|
| MD5 |
c8ec0f5bbb6217e6d04a071ecb22c5f6
|
|
| BLAKE2b-256 |
e85b6918668aae7a0211c5f3d48af1ad807eb681af0e518be90d46d416cfa562
|