Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/buttondown/django-typescript-routes
Generate Typescript routes from a Django URLconf
https://github.com/buttondown/django-typescript-routes
django python typescript
Last synced: about 1 month ago
JSON representation
Generate Typescript routes from a Django URLconf
- Host: GitHub
- URL: https://github.com/buttondown/django-typescript-routes
- Owner: buttondown
- License: mit
- Created: 2023-08-17T19:27:17.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-08-17T20:01:04.000Z (over 1 year ago)
- Last Synced: 2024-05-28T17:34:01.894Z (6 months ago)
- Topics: django, python, typescript
- Language: Python
- Homepage:
- Size: 17.6 KB
- Stars: 23
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- stars - buttondown/django-typescript-routes - Generate Typescript routes from a Django URLconf (Python)
- stars - buttondown/django-typescript-routes - Generate Typescript routes from a Django URLconf (Python)
README
# django-typescript-routes
Meant as a spiritual successor to [django-js-reverse](https://pypi.org/project/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:
```python
urls = [
path(
r"about",
about,
name="about",
),
path(
r"/",
subscribe,
name="subscribe",
),
path(
r"//subscribers//success",
subscription_success,
name="subscription-success",
),
]
```into:
```typescript
const URLS = {
about: () => `/`,
subscribe: (username: string) => `/${username}`,
"subscription-success": (username: string, pk: string) =>
`/${username}/subscribers/${pk}/success`,
};
```## Quick start
1. Install:
```bash
poetry add --dev django-typescript-routes
```1. Add `django-typescript-routes` to your `INSTALLED_APPS` setting:
```python
INSTALLED_APPS = [
...,
"typescript_routes",
...
]
```2. Run the management command to print out the typescript file:
```bash
python manage.py generate_typescript_routes --urlconf projectname.urls > assets/urls.ts
```