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
- 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 --conf 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.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c55b1732648a11a41f34ec84b3b799e3ac72f4b7a099dc8981308470424bdf1e |
|
MD5 | e24d42bc563d4ca4cdfb7efca98bf3bd |
|
BLAKE2b-256 | 4361602f96de68fd98a439acdf8d77d9651ba1a0f8f582ab43d2bf4a99e3e6bd |
Close
Hashes for django_typescript_routes-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6450cccaaa84b55a758fd2c58f49965806fc9da1836b2f1a43390d10dc85377 |
|
MD5 | f71eae0bb3b17e7d30260fdaf6d4b594 |
|
BLAKE2b-256 | aa4aac4ce725b41ab41fb46cad0815babae8ac25726800141ef48f30d48add58 |