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
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
Close
Hashes for django_typescript_routes-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | aee22804461f4e9def2f9a99dd3f1e38f84209d1702dfb2d50f417376838daa1 |
|
MD5 | 7d2d4393623ce80589b0e9273d39f273 |
|
BLAKE2b-256 | 656e4fa0b567d8c1bbebea776a539ec12055184cb1851d183926c5bd4648ce60 |
Close
Hashes for django_typescript_routes-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 719aa87ac77d2cd9cf0f99f1226f86919023f1668af7f4c525ec0b14da62f1f7 |
|
MD5 | f30629a66506dd9439a87ffcb6b5a8ce |
|
BLAKE2b-256 | 3bbf9da211f630793ddbd14f1bc63e5b2a24b4605b33cd1fc63f0617331ab59e |