Show HN: DJX – Django 的约定优于配置 (Rails 风格的命令行工具)
2 分•作者: RedsonNgwira•5 个月前
嗨 HN,
我是一个来自马拉维的自学开发者,我构建了 DJX,因为我厌倦了反复编写相同的 Django 样板代码。
Django 很强大,但开始一个新功能意味着手动创建模型、视图、模板、URL,并将所有内容连接在一起。Rails 在 20 年前就通过脚手架解决了这个问题。Django 应该拥有同样的功能。
DJX 将“约定优于配置”带到了 Django:
```
pip install djx-cli
djx new myblog && cd myblog
djx scaffold Post title:string content:text published:boolean
python manage.py migrate && python manage.py runserver
# → http://127.0.0.1:8000/posts/ — 完整的 CRUD 操作。完成。
```
就是这样。你将获得列表、创建、编辑和删除视图以及模板,所有这些都自动连接起来。
其他命令:
- `djx routes` — 查看所有 URL 路由(Django 并没有内置这个功能)
- `djx destroy scaffold Post` — 干净地移除生成的代码
- `djx add django-crispy-forms` — 安装并自动添加到 INSTALLED_APPS
- `djx model`,`djx controller` — 单独生成部分代码
它遵循 Rails 的约定:复数应用名称、RESTful URL、自动时间戳和合理的默认设置。
我构建这个是因为我希望 Django 开发感觉像 Rails 一样快。它还处于早期阶段,但它已经在每个项目上为我节省了数小时的时间。
PyPI:[https://pypi.org/project/djx-cli/](https://pypi.org/project/djx-cli/)
GitHub:[https://github.com/RedsonNgwira/djx-cli](https://github.com/RedsonNgwira/djx-cli)
非常欢迎您的反馈和贡献。还有哪些类似 Rails 的功能可以使 Django 开发更快?
查看原文
Hi HN,<p>I'm a self-taught developer from Malawi, and I built DJX because I was tired of writing the same Django boilerplate over and over.<p>Django is powerful, but starting a new feature means manually creating models, views, templates, URLs, and wiring everything together. Rails solved this 20 years ago with scaffolding. Django deserves the same.<p>DJX brings convention over configuration to Django:<p><pre><code> pip install djx-cli
djx new myblog && cd myblog
djx scaffold Post title:string content:text published:boolean
python manage.py migrate && python manage.py runserver
# → http://127.0.0.1:8000/posts/ — full CRUD. Done.
</code></pre>
That's it. You get list, create, edit, and delete views with templates, all wired up automatically.<p>Other commands:
- `djx routes` — see all URL routes (Django doesn't have this built-in)
- `djx destroy scaffold Post` — clean removal of generated code
- `djx add django-crispy-forms` — install and auto-add to INSTALLED_APPS
- `djx model`, `djx controller` — generate pieces individually<p>It follows Rails conventions: pluralized app names, RESTful URLs, automatic timestamps, and sensible defaults.<p>I built this because I wanted Django development to feel as fast as Rails. It's early stage, but it's already saving me hours on every project.<p>PyPI: <a href="https://pypi.org/project/djx-cli/" rel="nofollow">https://pypi.org/project/djx-cli/</a>
GitHub: <a href="https://github.com/RedsonNgwira/djx-cli" rel="nofollow">https://github.com/RedsonNgwira/djx-cli</a><p>Would love your feedback and contributions. What other Rails-like features would make Django development faster?