Hacker News new | past | comments | ask | show | jobs | submit login
Django 1.4 final released (djangoproject.com)
359 points by pythonist on March 23, 2012 | hide | past | favorite | 58 comments



Release notes here: https://docs.djangoproject.com/en/dev/releases/1.4/

Some things to really dig:

    * better password hashing (bcrypt, etc...)
    * time zone support
    * built in selenium testing support
    * bulk insert Models
    * prefetch_related() (efficiently join m2m)
    * SELECT FOR UPDATE support
    * easy signing of cookies
    * better project templates (basic scaffolding)
There are lots more... big release. Thanks to the all folks behind it.


Time zone support! This has always been one of the most painful things to manage IMHO. Also this little gem caught my attention...

  * The if template tag now supports {% elif %} clauses.


I've found using Jinja2 templates (http://jinja.pocoo.org/docs/ ) is a lot easier than dealing with the Django template language. Django also makes switching template languages quite easy.


I believe Jinja2 is also a lot quicker, but the Django developers want to catch up.. so that's something.


It's a great release, but bulk_insert is really really dangerous because it apparently doesn't call the save() method nor the pre_save or post_save signals.

I don't like this because a lot of us put validation logic in Model#save and use the signals to trigger the search indexer, and so forth. This behavior is definitely going to catch some people off guard and it's bound to lead to serious bugs.

I understand why they don't call Model#save for every object, but I think they should have introduced something like Model#validate which is called before every save (including the new bulk inserts) so you still get a place to put custom validation logic that you know will get called the moment something is placed in the database. So now inserts are faster but at the expense of correctness. I'm not convinced that's a good trade off.

Oh, and for some reason bulk updates are completely missing, even though it seems natural to add bulk_insert and bulk_update at the same time.


This is the correct behavior, really. Bulk insert is not for cases where you have complex per-record validation or processing logic that also needs to be run in the application layer. It's for "I have all this data ready to go, now just shove it in there as efficiently as possible". If you need to have validation and additional per-record processing, signals, etc., insert the objects through the ORM normally. Yes, it'll be slower, but that's the price you pay for doing per-record processing.


To add to this, you could write your own validation method for a model and have your model's save method call this.

When processing bulk data sets you can iterate over calling your own validation then perform bulk insert knowing its validating. And your save will still validate as before.



And bulk updating also doesn't run any signals or the save method...


Nor should it. It's for inserting a bunch of stuff, really fast. You can just do normal saves if you want to call the save() method.


I've created a project template that I consider - and hope - is an improved project template for most.

http://amccloud.com/post/14689947527/django-1-4-custom-proje...


All heavy hitting features. I've been begging for "SELECT FOR UPDATE" support forever, and django-bcrypt is in my bootstrap requirements.txt.

Does anybody have any reference to the scaffolding features? This might be the first I've heard of it.


Does anybody have any reference to the scaffolding features? This might be the first I've heard of it.

Yeah, see https://docs.djangoproject.com/en/1.4/ref/django-admin/#djan... and https://docs.djangoproject.com/en/1.4/ref/django-admin/#djan....

It's really very simple: you just create a directory of files and point startproject/startapp to that directory with the --template flag. Files are copied over into the new app/project, with some simple replacements for things like the project name.

You can check out Django's source for the built-in one, or if you poke around on Github you'll find some others. Here's one, for example: https://github.com/amccloud/django-project-skel/.


Django-bcrypt should still be installed with those old projects while you upgrade. Be careful with that there are some gotchas


   * *args and **kwargs support for template tag helper functions


Another new thing you didn't mention is the new list filter framework for the admin. I've found it really useful in my projects.


Cool, finally has what the big players have had for over 5 years (10 for some of the new features).


For anybody interested in trying out the new templating system, this one has been active for a little while now and is based on the work of Mozilla and it has HTML5 boilterplate + Twitter bootstrap already, as well as Jinja2, Sphinx, Django-Admin-Panel, Markdown, Celery, South and some other niceties:

Check it out: https://github.com/xenith/django-base-template

or just..

    django-admin.py startproject --template https://github.com/xenith/django-base-template/zipball/master --extension py,md projectname


I made a template that I mentioned above that is a bit simpler and is self documenting.

    django-admin.py startproject --template  https://github.com/amccloud/django-project-skel/zipball/master --extension py,md yourprojectname


Is the Django-Admin-Panel different than the default? I can't find a project page for anything named so.


Any recommended resources on getting started with Django, or are the official docs sufficient?


Official docs are some of the best of any project (save maybe the best practices for view creation...).

I'd recommend skimming through a few Django applications to get an idea of structure, one I know off the top of my head (as I wrote it): https://github.com/zapier/django-knowledge

Read the excellent Yipit Django blog (http://tech.yipit.com/). Especially their post about learning Django: http://tech.yipit.com/2012/02/28/183772464/


Django Book is ancient and obsolete as hell, but if you can fix most of the breakages, it is one of the best resources there are.

I don't agree that the documentation is great, but it is definitely good, although it is frustratingly lacking in some areas - although you won't run into that soon.

My suggestion is to try it in this order:

1. Django Book

2. Django Project Intro[1]

3. Django by Example[2]

The best tip to learning Django is to use #django on freenode[3]. People there will not do your work for you, but interactive live help is simply the best there is, unless you know forums like Something Awful where you can write out long-form questions to people who'll respond in the same fashion.

EDIT: I seriously wouldn't bother with any of the Django (book) books out there.

[1]: https://docs.djangoproject.com/en/dev/intro/

[2]: http://lightbird.net/dbe/index.html

[3]: http://webchat.freenode.net/


The official docs are more than sufficient. They were one of the main reasons i picked up Django. Or you can watch the following:

Introduction to Django http://pyvideo.org/video/604/introduction-to-django

and if you want to venture further down the rabbit hole

Django in Depth http://pyvideo.org/video/610/django-in-depth


The slides for "Introduction to Django" really need to be published. That video is impossible to follow without them.


The official docs are outstanding, some of the best documentation of any open source project I have used.


The official website is more than enough, so long as you have python experience. If not, you should start with Dive Into Python (or something similar) at the same time at least.

If you have any MVC framework experience at all django is relatively straightforward.


How's your Python? I hated Django when I was learning it and Python at the same time, but having abandoned Django (and sticking with plain old Python), when I revisited it a few years ago, things were dramatically easier.

In short, if your Python skills are passable, I'd say the docs at djangoproject.com[1] are more than sufficient. If not, I'd guess you might have troubles.

[1] - https://docs.djangoproject.com/en/1.4/


FWIW - I learned Python by learning Django, and loved it. Probably a meaningless datapoint, but I thought I'd offer it anyway.


I got my initial exposure that way, but I had a hard time putting all the pieces together until I pulled Django out, and got a better understanding of which things came from where.

I should probably also point out that I'd only dealt with web languages before that point (PHP, ASP Classic, etc), so that's probably a negative point for me.

Everybody's different, for sure. For me, my Django suffered until I understood Python.

Can I ask what your pre-Django experience was? I wonder if there's any significance.


Maybe previous experience is significant - I learned to program building websites (HTML -> early CMSes -> PHP), then did a computer science degree (mostly Java, though I did a bit of Ruby on Rails), then got a job in C++ (where I still work, 3 years later), which I'd been doing for a year or so by the time I picked up Django.

To be honest, I suspect my Python's not great - I probably ought to spend more time just writing Python - I'd hazard a guess that less than 20% of the time I spend building websites with Django is spent writing Python (most is probably spent fiddling around with HTML/JS). I can always get by - but every once in a while I learn something new that I wish I'd known about long before (I remember learning about list comprehensions at an intro to Python talk at Stack Overflow DevDays after I'd been using Python for about a year!).


Me too. iirc Alex Gaynor as well



Official docs are great, also check out the django book http://www.djangobook.com/


Sadly the django book is very old and not updated since a long time.


Since Railscasts.com is now making money through subscriptions, I'm surprised nobody's made a Djangocasts.com. Back when I was only flirting with web frameworks, Railscasts' bite-sized videos were the easiest way to get a taste of Rails.


You'd be hard-pressed to find a better resource than the official docs.



Dear prefetch_related(), my M2M-relationships have been waiting for you for soo long, glad you are finally with us.


Man, I just went through the 1.3 tutorial TWO days ago. Does anyone that uses Django know if the changes are huge? I guess I will be going through the 1.4 tutorial this afternoon.



Thank you! Everything I read went over my head, which is good since it means I haven't gotten that far yet :)


good for you, happy coding then ;)


I have a Django app in its early stages using 1.3, would it be a good idea to just transfer it over to 1.4? The only third-party app that it is using is django-registration...


Try it and see - if you're not using virtualenv - you should be. If it doesn't seem compatible, just install 1.3 back.


The main problems I ran into when upgrading were with the new timezone support, but it was easy to just disable it (set `USE_TZ = False`) until I have a real need for the feature (and the time to fix the issues it causes for current code).


I'm using a lot more (including django-registration) with 1.4, go ahead.


Damn, I just wasted 1 month rewriting a password hashing app.


Hopefully not bcrypt, since dwaiter already has that one solved with django-bcrypt[1].

[1] - https://github.com/dwaiter/django-bcrypt


Does anyone know a good way to find out whether your Django packages will break or work fine? I am currently using these:

    django-registration
    django-secure


1. Check the docs and release history of the projects/apps; if they have not been updated prior to v1.3, it's likely to break with v1.4.

2. Run the test suite of the apps.

3. Run the apps with v1.4 and warnings turned on via:

   python -Wall manage.py runserver.  
Not only will you quickly see what's broken, but Django will dump helpful deprecation warnings for things that will eventually break at some point.


Congrats all, new project due to be live in a month or so I'll keeping an eye on updates and might make the jump asap


I remember seeing that they would deprecate the {% url 'name' %} template tag without quotes. What happened to that?


Congrats to the team. Will have to check it out in the next few days.


I wish Django uses sqlalchemy as the default ORM instead of inventing a squared wheel.


How's SQLAlchemy working with MongoDB? I, for one, am very happy to be able to use MongoDB as a Django backend. I believe this is largely due to the fact that Django has never directly assumed data models to be stored in a SQL database, but has defined its own object abstraction layer instead.


You cannot have a sane ORM that works with nosql and sql databases without compromising features & complexity.

I am glad sqlalchemy deals with sql-only databases.

You don't need an ORM for nosql. A library suffice.


You cannot have a sane ORM that works with nosql and sql databases without compromising features & complexity.

Well, people don't need all the features all the time.

Else, they would use Oracle and not MongoDB.

In the same logic, they get by with Django ORM just fine.

As for the complexity, I don't think anyone ever called it complex...




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: