Skip to content

buttondown/django-typescript-routes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  1. Install:
poetry add --dev django-typescript-routes
  1. Add django-typescript-routes to your INSTALLED_APPS setting:
INSTALLED_APPS = [
    ...,
    "typescript_routes",
    ...
]
  1. 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

About

Generate Typescript routes from a Django URLconf

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy