Hacker News new | ask | show | jobs
by spapas82 3469 days ago
Merry christmas! For me it's Django for around 5 years. I use it for both personal and work projects for all the following reasons (they are well known but repetition is never bad):

* A great (really great) orm

* Best documentation I've ever seen in a project

* Predictable, no magic

* Easy to start but very powerful forms

* Great community, positive attitude, always willing to help

* Batteries included and, for anything missing, lots of add-ons (in the form of apps) for all your needs

* It's in python and supports both 2 and 3

* Good i18n support (english is not my primary language)

* Good templating

* MVT (model view template) architecture works great, especually after you switch to CBVs

* Great support for REST (through django-rest-framework)

* Easy and to-the-point project configuration supporting multiple deploys (development, production etc) and non-commited to vcs settings

I've tried other frameworks in the past but I've always stuck in a missing feature or just wanted to do things in the django way.

2 comments

I've always been curious as to how you structure your models in Django.

I'm building a personal project in Tornado and MongoExpress, and the only thing I can see about structuring my models is to put all of them in one file called models.py

I'm used to the RoR way of doing things, so this seems very counter-intuitive to me.

In addition, whenever I try to break the classes into different files, I'm not sure of where to store my DB connection logic, and how to ensure that all models are accessible from the controllers.

Ideas?

You can make `models` a package, where `models/__init__.py` just imports models from the package's modules (`models/thingamabobs.py` and ` from .thingamabobs import Thingamabob`).

Also, you shouldn't need to worry about database connection logic in Django unless you're doing something very specific.

Depending on the situation, I think it's usually better to seperate the models to different apps instead of using a single app with a models.py-package. This way you'll have seperate views, forms, urls, admin, templates etc.

For common functionality (ie an abstract model or a mixin that is used/inherited by multiple models/views) I like to add another django app named common or core that is used by the other apps.

I'm using Tornado, not Django. I just want to use Django as an inspiration for my app structure.

The problem with Tornado is that it doesn't come with an in-built ORM like Django, which means I need to actually create a connection to the Mongo instance I'm using. Hence the confusion. Python doesn't have initializers like Ruby does (that I know of).

I've never developed using Django. How does it compare to Wordpress? Or under what situation is it preferable to Wordpress?
But you cant compare Wordpress with Django, Wordpress is not a web framework is just a CMS for blogs.

Or am i wrong?

PS... Django <3

I have done little Wordpress development (just some plugin for a prototype that my company wanted). But I don't see anything that prevented it from being used to develop a web application since the theme/plugin system seems to fulfill everything. Django also describes itself as a CMS platform on their website so I kind of thought they are comparable.

Just wanted to make sure I know what I'm getting before I jumps in further into either Wordpress or Django :D

Wordpress is technically capable of being used to build large apps, but, you're going to be rolling your own everything. Whereas a framework, is, well, a framework that has standardized and cleanly extensible ways of doing core functionalities X, Y, and Z.

Wordpress is old, and they've built up a shit-ton of technical debt for the sake of BC. To put it bluntly, it's not a pleasure to work with, at all. On the up side, something like 20% of the surface net runs on Wordpress. There's a huge market for WP skills, and it's got enormous mindshare amongst non-technical types. If you want to invest effort in WP, do it because of the adoption metrics; if you're more technically oriented, pick Django (or Laravel/Symfony if PHP is more your speed).

Well, wordpress is a cms that, through custom work, can be used as a web framework (ie you can built other, non-cms, things with it). Django is a web framework that can be used to build a cms.

Actually there are some great cms built on top of django, for example django-cms or wagtail!

If you start from scratch and want to build a simple cms it will be easier to do it with wp, if ofcourse you tolerate php - some people won't use php for reasons that should be well known to hn readers. However, for any other web development I recommed using django (or another normal web framework).

Using wp to build non-cms stuff reminds me the "when your only tool is a hammer everything looks like a nail" argument! You may use your hammer to cut (break) wood but using your saw would be easier and safer!

I've seen that line of thinking with newer devs who don't understand the right tool for the job. Unless your client specifically wants a custom solution for a custom purpose, you will spend the first week writing a CMS in Django and the next 20 recreating .1% of WP's functionality because you didn't anticipate the full list of client's needs correctly.
>Django also describes itself as a CMS platform on their website so I kind of thought they are comparable.

What?

Django website have "The Web framework for perfectionists with deadlines".

You can compare WP with Drupal or Joomla. With Django you can build you own CMS.

D:

Sorry, one of the first links when I searched for Django on Bing (currently in China) is django-cms.org.

If you're tied to wordpress, I'd take a look at laravel it's built in php, has the largest community as far as PHP frameworks go, and you can literally build anything, and incorporate packages from packagist, etc... Wordpress is slow, has a HUGE codebase and you can't really control it as granularly as you can a fresh laravel app.
Django is a framework, Wordpress is a CMS. Django aims to be able to build pretty much any web application, Wordpress aims to make it easy to add and display content.

I'd use Wordpress when building simple websites that serve as landing pages or blogs. If the main use for the site is showing some basic static info that never changes or the owner coming in, writing a few articles and clicking save, then Wordpress might be a good fit.

I'd use Django when building more complex websites and web applications where a CMS just doesn't fit due to the complexity of the logic, functionality or data. For example you might build an inventory management system with Django since it can have complex business logic and the data doesn't really fit a blog format. You might build an online store with Django, since you need to model and handle logic for products, inventory, payments, customers and such.