惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

雷峰网
雷峰网
爱范儿
爱范儿
宝玉的分享
宝玉的分享
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - Franky
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 三生石上(FineUI控件)
人人都是产品经理
人人都是产品经理
阮一峰的网络日志
阮一峰的网络日志
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
博客园 - 聂微东
大猫的无限游戏
大猫的无限游戏
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
博客园 - 叶小钗
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
博客园 - 司徒正美
博客园 - 【当耐特】
IT之家
IT之家

Buttondown's blog

Email could have been X.400 times better The physicists who convinced Fermilab to send Brazil's emails Slack webhooks Better in-app previews Analytics 3.0 Subscriber ID variables Comments! Send latest premium action Automation filtering Free API subscribers Surveys in automations Reply to replies Labels for RSS feeds How Jeremy Singer-Vine curates curious datasets for readers 2023 (and what's next) Email vs web content Sort by engagement Better gift subscriptions How Andy Dehnart built a career reviewing television New email template Email-based automations Opt-in reply tracking Automatic alt text More social network integrations Sort by metadata Overlarge image warnings Automation tag actions Pause emails mid-flight Search tags and automations Gift via automations
Generating a Typescript router in Django
Justin Duke · 2022-10-26 · via Buttondown's blog

Nerd alert!

This post is a small technical snippet for Python and Django programmers. If you don't know what those proper nouns mean, don't worry — feel free to skip this post.

Buttondown has used django-js-reverse since its inception to route backend API urls from the Django backend to the Vue frontend.

This has been (not to damn with faint praise!) better than nothing: some kind of syncing mechanism certainly beats having to manually correlate backend routes with frontend definitions. But there are two nits I've had with the package:

  1. The package isn't TypeScript-friendly; errors in routing or invocation (such as calling Urls.email_detail() instead of Urls.email_detail("foo")) are not caught until runtime.
  2. The package does some light metaprogramming to allow you to refer to a route not just as its name (email-detail) but via camel or snake case (Urls.emailDetail() or Urls.email_detail()). This attempt at ergonomics makes it trickier to actually find all invocations of a route at a glance.

Naturally, I thought to myself: why not try my hand at building a better version? I'm happy to share that it was fairly painless: while I'm still a little bit away from formally open-sourcing this as a package (there are a number of administrative tasks like registering with PEP and settling on a name that I need to take care of), here is the total implementation — 34 lines of Python and 4 lines of templated TypeScript.

I am confident this implementation is missing many, many, many edge cases. It does not handle URL namespacing nor non-string parameters, nor I'm sure many other things. But it is a step change improvement to Buttondown's codebase, and I'm excited to have it. Please let me know if you find it useful, or if you have any feature requests/suggestions — I promise to update this blog post with a link to the repository once it's published to PEP.