Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
The Django book, Second Edition. (djangobook.com)
79 points by socratees on Jan 9, 2009 | hide | past | favorite | 21 comments


Oh good. It's not finished yet. I was afraid that I was going to have to buy it again when I hadn't finished the first edition. Apparently they can write faster than I can read.


I am really glad to see that they are updating it for Django 1.x. I have not programming background but have been trying to decide on a web-focused language/framework to learn, and Django was highest on my list. Up until now, however, there weren't any online resources (that I had found) that detailed getting started with Django 1.x. I've started looking at Ruby/Rails, but may have to reconsider my decision now that there is a good resource available.


The main Django docs are really good and up to date. Not a book, but if you have the concepts down everything you need is there.


Agreed, they're just 4 pages, but they cover a great deal and you can definitely start a decent site after going through the tutorial. At its end, it also points you to more docs that describe specific things such as forms, urls, and caching in great detail.


Actually if you generate a PDF off the official Django documentation it comes out as nearly 800 pages!

http://blog.clintecker.com/post/66123727/django-1-0-2-docume...


Good point, I meant that the introductory tut was only 4 pages. THanks for correcting me!


i still don't get the instantiation thing why datetime.datetime.now() ?? what's special about saying it twice? noob question but a link somewhere that explains this would be appreciated.


Basically, what it comes down to is Python's explicit over implicit policy. First, unlike PHP, not everything in the Python language is automatically included in every file. You explicitly import things. datetime is a module in the standard Python library. It includes several things: datetime, time, date, timedelta. . . So, often what you want is a datetime object from the datetime module, but you could do datetime.date.today().

One of the nice things about Python is that you should be able to see where something comes from anytime you're using it. If you're referencing something, it will either be defined in that file or be defined by something imported at the top. So, if you see "Site.objects.get_current()" you can easily search the file for where Site comes from. Maybe it's a Site class defined in the file itself. Maybe it's imported from django.contrib.sites.models. Maybe it's from somewhere else. The nice thing is that you can easily see where it comes from so that you can look up that code.

This is very unlike many languages. PHP's include()/require() could execute anything when you call them and define any number of things and you might not know where they come from so easily. I get push back on this from some of my friends who argue that good IDEs should track that for you, but I like that there isn't the ambiguity in Python.


To be fair, an import in Python could execute anything, too.


True. It would be much nicer to have a now method in the datetime module so that we could just do import datetime; now = datetime.now()


The first is the datetime module. The second is a class.

It comes down to how you import it. These two bits of code are equivalent:

# Example 1

import datetime; print datetime.datetime.now()

# Example 2

from datetime import datetime; print datetime.now()

I generally prefer "import FOO" over "from FOO import BAR", which is why you see example 1 used in the Django Book.


The datetime module was also written before the Python style conventions were created.

If the datetime module was written today, it would make a bit more sense looking like this:

import datetime

datetime.DateTime.now()


Or it might have just been merged into the time module. The datetime module is mostly a single class which wraps the functions in the time module and adds a few convenience methods. I wouldn't be surprised if the reason for the separation is just historical -- say, time was written to match the C library, and later someone donated datetime as a set of utilities with an OO interface.

Anyway, since the common utilities in that are all attached to the datetime class in that module, there's no harm in importing the class directly. You could even fix the naming yourself, if you were so inclined:

    from datetime import datetime as DateTime
    DateTime.now()


So a `DateTime = datetime' in the module would let newer code look more conventional?


It would make the datetime class look more like other class names, but I'd strongly recommend against doing this. The Python community values consistency in the way that code is written (TOOWTDI) and this would be a sharp departure from that.


Fair, but maybe some class renames wouldn't be a bad idea for the v2 to v3 switch over. I don't know what the priorities are or what the bar is for changes that make the cut, so don't quote me on this :-)


As others have mentioned, datetime is basically a module that deals with everything related to dates and times. datetime.datetime is a class that deals specifically with date and time combinations. So basically datetime.datetime.now() would return something that contained both the present date and time, while datetime.time deals with time objects.


thanks guys


Awesome! Djangobook.com and the official docs are how I learned Django. Djangobook.com is definitely a great place to start when then you can immerse yourself into the official docs (digging deep inside them) or the actual Django code, which can teach you a lot.


I tried making a simple Django app on Google app engine about 5 months ago, and I could never get it running. It left a bad taste in my mouth. Maybe it was just half baked on Google app engine at that time?


Yes. GAE is hardly Django. It's still a cognitive leap from PHP to MVC, but I recommend doing it outside of GAE.




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

Search: