I think people tend to consider Django either for building old-school, industrial-strength monolith apps or for APIs and using something like React for the front-end. I’m here to tell you that plain old Django is a great option even for your personal websites! In my opinion, if you need a database, you should use Django1.
Django is considered a “batteries-included” framework, and those batteries are awesome. These are the things that keep me using Django over any other framework.
The Django ORM is a huge reason to use the framework. I’m flabbergasted that not all web frameworks include an ORM. Unless you’re a huge fan of writing SQL from scratch, this is the right way to build apps. You define models, you create database migrations from those models (mostlyautomatically), run the migrations on your database and you’re good to go! No writing half-assed models plus a series of migrations where you can sort of extrapolate the schema2.Allthe information you need about your data is in your models.py file and everything flows from that.
This is the big one. It’s not a CMS; it’s more of a GUI for the ORM. After you define your models you can, withvery littleconfiguration, manage that data without having to write any CRUD code. It’s not the front-end of your application. It’s not a CMS for end-users (probably). It’s a way for administrators to easily make changes to the site.
This is very near and dear to my heart, but most of the rest of our industry seems to have forgotten. Simply put; base-level functionality should be possible even when JavaScript fails. Your app should be able to at least limp along without front-end scripting. Doing that with a SPA is a nightmare. Doing it with a real backend framework plus a tool like htmx or Unpoly is trivial. You just have to change your perspective from the status quo to common sense.
While traditional application frameworks use the Model, View, Controller design pattern; Django names their elements a little differently.
This is a solved problem in Django. It’s really nice! There’s lots more to know about it, and youshouldlook at the generated migration files before running them,andthere are times when you’ll need to do this stuff more manually, but this is the crux of using it:
./manage.py makemigrations # It tells you what it did. ./manage.py migrate # Database updated!
That’s it! ?
Here’s where I shill for my own little project. The good news for you, solo developer that I imagine is reading this, is that it’s free for non-commercial use. If you end up using it and it helped you build a commercial application, it’s only $100 USDone time. C’mon, that’s quite a value!
Even if you don’t end up using the whole kit, I urge you to look over the techniques I use in the code. That’s hard-won stuff after using Django almost since its beginning. I went through a phase of using it with Docker and Postgres, but I really believe this istheway for 99% of folks who want to give Django a try. SQLite is amazing.
Unfortunately, this is the main downside of choosing Django over other options targeted at personal websites. With Blaze.horse, I’ve tried to set you up for an easy time, but it’s still fiddlier than it ought to be. There are some up-and-coming projects that give me hope, such as Button and Appliku, but I’m personally happy with Fly for now.
After reading this, I hope you’ll keep Django in mind the next time you need build something. Let me know if I can help!
If you need a CMS, you should use Kirby. Youcertainlyshouldn’t be using a static site generator if you need a CMS. FFS ↩
Laravel ↩
The above is the detailed content of Django is for everyone.. For more information, please follow other related articles on the PHP Chinese website!