You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

django-typescript-routes

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

django-typescript-routes

Generate typescript routes from a Django URLconf

0.3.0
pipPyPI
Maintainers
1

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:
uv add django-typescript-routes
  • Add django-typescript-routes to your INSTALLED_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

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts