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:
poetry add --dev django-typescript-routes
- Add
django-typescript-routes
to yourINSTALLED_APPS
setting:
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
Release history Release notifications | RSS feed
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
File details
Details for the file django_typescript_routes-0.2.0.tar.gz
.
File metadata
- Download URL: django_typescript_routes-0.2.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.11.0 Darwin/24.0.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7c16e091f21c5b5665ddae07bf55bddc6a6215516170122c4a71df596df1281 |
|
MD5 | f92cf60d8b7711c5f4dd801ea9380954 |
|
BLAKE2b-256 | 705d25d2bc9f137d992c67063a8e9b452f9c7e6a54f2fb6ea9460b4066219d48 |
File details
Details for the file django_typescript_routes-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: django_typescript_routes-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.11.0 Darwin/24.0.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c37114d0d374b47f3f12459f0f919c9cb20b2d0e48f0fe3e2ba27fed64feb2ce |
|
MD5 | 66054043519a9033a61a7aaaa3b42824 |
|
BLAKE2b-256 | b12ac2a40bd9c6ced138dbe1cf6f080d299a65db19169df72f51633534416347 |