展示HN:DJX – Django的约定优于配置(受Rails启发的命令行界面)
嗨,HN,
我是一名来自马拉维的自学开发者,我创建了DJX,因为我厌倦了一遍又一遍地编写相同的Django模板代码。
Django功能强大,但启动一个新功能意味着需要手动创建模型、视图、模板、URL,并将所有内容连接在一起。20年前,Rails通过脚手架解决了这个问题。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?