Practical Django Projects
Chromodromic writes "Apress's newest Django offering, Practical Django Projects by James Bennett, weighs in lightly at 224 pages of actual tutorial content, but trust me, they're dense pages. Filled with pragmatic examples which directly address the kinds of development issues you will encounter when first starting out with Django, this book makes an important addition to the aspiring Django developer's reference shelf. In particular, the book's emphasis on demonstrating best practices while building complete projects does an excellent job of accelerating an understanding of Django's most powerful features — in a realistic, pragmatic setting — and which a developer will be able to leverage in very short order." Read below for the rest of Greg's review.
Practical Django Projects
author
James Bennett
pages
256
publisher
Apress
rating
8/10
reviewer
Greg McClure
ISBN
1-59059-996-9
summary
A practical introduction to the Pythonic Django web framework.
This book serves an important function by providing progressive, useful examples of Django's role in the development of realistic projects. During the course of the tutorial you build three basic apps: A simple brochureware-oriented CMS, a complete blogging system (with Akismet spam protection and RSS feeds, among other features), and a social code-sharing site similar to that found at djangosnippets.org (with account signups, syntax highlighting via pygments, and bookmarking features — the whole enchilada). You may or may not find these projects
immediately relevant to your work or goals, but the projects themselves are really just platforms for delving into Django's nooks and general philosophy. It's an important point to make about the book especially, because though Django itself provides potent facilities for creating reusable code while preserving a high degree of flexibility, "magic" is kept to a minimum compared to some other popular frameworks. It follows that maximizing your knowledge of Django's inner workings through familiar paradigms is critical to making the framework perform to your best advantage. The book excels at accomplishing this goal.
Along these lines, a lot of territory is covered in a short span. You're introduced to a couple of Django's contrib apps — code which comes with a normal Django installation and which cleanly plugs into your own application while remaining extremely customizable. After being ushered through a straightforward installation and database configuration, your first exposure to development is through the contrib app most frequently lauded in the Djangoverse, Django's deservedly well known admin system. But immediately, emphasis is shifted from the basic features of the system to the ways it can be customized. This approach of introducing a feature and then modifying or extending it is repeated immediately with Django's Flatpages contrib app, a very basic CMS which, again, comes with Django and installs with a single line of code and one command.
By the time you've finished the third chapter, you've built the foundation of a typical brochureware site, complete with a working search system and a completely functional customized admin with which you may modify your content using a javascript-based HTML editor (TinyMCE). Pretty impressive for 41 fast-moving pages.
The strongest feature of the book, though, is not the speed or facility with which features are presented, but rather the way these features are always demonstrated with a mind to Django's strongest argument: how easy it is to create reusable code, once you understand the framework's approach. As you move through the next four chapters of building the blogging system, the establish-modify-extend technique of presentation does a good job of working you through various standard Django features — generic views (a very important concept which is illuminated nicely), code organization, ORM techniques, template inheritance, and so forth — and you're smoothly shown the ways by which you will be able to incorporate much of the code you write into your future work. As you begin your last project, the code-sharing app, you've gotten an overview of both coding and workflow techniques which work best with Django. The final chapters reinforce everything you've learned while still introducing new material on library integration, form handling and the newforms library, and code distribution.
The overall approach is very effective, though I found I had to trust the tutorial a little at first in order to get the most out of it. The projects initially seemed somewhat vanilla, so it wasn't until I really focused on the organization of the material that I discovered the book's strengths. Now I wish I'd had this book years ago.
Issues? I had only one, really. The material presents itself as a tutorial suitable for those who are just starting out with Python. For example, near the beginning of the material the def keywork is pointed out as the way Python functions are declared, and similar kinds of notes and comments pepper the tutorial, somewhat unevenly, as well. While I appreciate the impulse to make the material as accessible as possible, I'm skeptical of the book's role as truly introductory at that level, although I could see some experienced developers, especially those coming from other languages, benefiting from these quick notes. But my feeling in general would be that if you're so new to Python that the def keyword is a revelation, you might be better off starting elsewhere before you dive into Django.
This is a minor point, though, and if you're willing to give the material the time, you'll appreciate what Django has to offer more and more with every page. The book maintains a brisk pace which I truly appreciated. And if you've struggled with Django in the past, or you've wanted to learn more about what to do beyond getting the admin running, "Practical Django Projects" is an excellent foundation for your Django education. I absolutely recommend this as the Django book I've found to be, by far, the most useful.
You can purchase Practical Django Projects from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
Along these lines, a lot of territory is covered in a short span. You're introduced to a couple of Django's contrib apps — code which comes with a normal Django installation and which cleanly plugs into your own application while remaining extremely customizable. After being ushered through a straightforward installation and database configuration, your first exposure to development is through the contrib app most frequently lauded in the Djangoverse, Django's deservedly well known admin system. But immediately, emphasis is shifted from the basic features of the system to the ways it can be customized. This approach of introducing a feature and then modifying or extending it is repeated immediately with Django's Flatpages contrib app, a very basic CMS which, again, comes with Django and installs with a single line of code and one command.
By the time you've finished the third chapter, you've built the foundation of a typical brochureware site, complete with a working search system and a completely functional customized admin with which you may modify your content using a javascript-based HTML editor (TinyMCE). Pretty impressive for 41 fast-moving pages.
The strongest feature of the book, though, is not the speed or facility with which features are presented, but rather the way these features are always demonstrated with a mind to Django's strongest argument: how easy it is to create reusable code, once you understand the framework's approach. As you move through the next four chapters of building the blogging system, the establish-modify-extend technique of presentation does a good job of working you through various standard Django features — generic views (a very important concept which is illuminated nicely), code organization, ORM techniques, template inheritance, and so forth — and you're smoothly shown the ways by which you will be able to incorporate much of the code you write into your future work. As you begin your last project, the code-sharing app, you've gotten an overview of both coding and workflow techniques which work best with Django. The final chapters reinforce everything you've learned while still introducing new material on library integration, form handling and the newforms library, and code distribution.
The overall approach is very effective, though I found I had to trust the tutorial a little at first in order to get the most out of it. The projects initially seemed somewhat vanilla, so it wasn't until I really focused on the organization of the material that I discovered the book's strengths. Now I wish I'd had this book years ago.
Issues? I had only one, really. The material presents itself as a tutorial suitable for those who are just starting out with Python. For example, near the beginning of the material the def keywork is pointed out as the way Python functions are declared, and similar kinds of notes and comments pepper the tutorial, somewhat unevenly, as well. While I appreciate the impulse to make the material as accessible as possible, I'm skeptical of the book's role as truly introductory at that level, although I could see some experienced developers, especially those coming from other languages, benefiting from these quick notes. But my feeling in general would be that if you're so new to Python that the def keyword is a revelation, you might be better off starting elsewhere before you dive into Django.
This is a minor point, though, and if you're willing to give the material the time, you'll appreciate what Django has to offer more and more with every page. The book maintains a brisk pace which I truly appreciated. And if you've struggled with Django in the past, or you've wanted to learn more about what to do beyond getting the admin running, "Practical Django Projects" is an excellent foundation for your Django education. I absolutely recommend this as the Django book I've found to be, by far, the most useful.
You can purchase Practical Django Projects from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
Here's a BUNCH of 'em!
Any technology distinguishable from magic is insufficiently advanced.
What's django? Hardware? Software? Language? The fine article doesn't really clue me in.
Should I imagine a beowulf cluster of these? Praise our new django masters? Profit? Or pour hot grits into my pants?
Who would win this election: Andrew Weiner vs Andrew Weiner's weiner.
I must be getting old. Never heard of this before, so the article was confusion at first. For info: http://en.wikipedia.org/wiki/Django_(web_framework)
I'm getting ready to port a fairly large web app from Zope to either Django or Turbogears (easier development, more scalable for us, etc.). From what I've heard, Django is kind of the Ruby On Rails of the Python world, and while outstanding for writing small mostly-read apps, it's not the greatest for large interactive applications. Conversely, Turbogears seems to have the reputation for a higher initial learning curve and startup cost, but better interactivity.
Any thoughts on the matter? I've used Django for some small projects and my experience kind of mirrored what I'd read: it's brilliant when you want to work with it, and a complete PITA when you're trying to do something unexpected. I haven't written anything with Turbogears yet so I can't personally compare them.
No, I'm not going to make my decision solely on the opinions of Slashdot. Consider this the start of my research, not the end. :-)
Dewey, what part of this looks like authorities should be involved?
I just got a newsletter about a sale at Bookpool.com for APress books. APress books are 45% off until 8/31.
This particular book is $5 cheaper at Bookpool.com than Amazon right now.
In Soviet Russia, I ruled you
Storm Dtroopers were imperfect clones of Django.
Dboba is a perfect clone of Django.
If you want to stop the Django process, you have to su to Windu and kill -9 Django
If you're looking for Dboba, try this command: cat \dev\sarlac | grep Mandalorian
I recently had a look at web application frameworks for some new development and ended up doing it with Django.
I find it handy. It's logically put together, the Python back end is fast, and, once you figure out a few basic concepts, you can put web apps together very quickly. The template system is particularly clever. I find that I like to set up my database tables first, then let Django create the model classes. Not the other way around. I also like to do table joins as views in the database, rather than gluing things together in Django. YMMV.
My last experience with web application development was with Tomcat. I still have nightmares. :-(
...laura
Only a day ago I would have been asking the same question. I have been a long time Java Developer and decided to trying deploying an application to the Google App Engine. Unfortunately, for me at least, only Python is supported so I have been forced to take a deeper look into Python.
The Google App Engine already has the Django libraries available. It's seems like a pretty useful template system, however I really wish they had chosen to use xml tags instead of parenthesis tags so that native xml tools, even browsers would display and work on the raw template more effectively.
On a side note, I have a question for any Java to Python converts out there. I am using Pydev for Eclipse, but I am missing the compile-time checking of static types, method signatures, etc. I've already experienced a few cycles of correct, save and repeat to find simple typos. I feel like I am back in the days of when I was Perl hacking. I know if I had unit tests for this it would make things a little better, but unit tests can't always cover 100%. Until I get to try the junit equivalent for Python (whatever that is), how do the rest of you deal with finding bugs that would have been compile time errors in other languages?
I'm just finishing up a project with django. It is a lot of fun, quick, and useful. It is very well designed. One issue, however, is that it is still changing rather quickly. Things in version .95 or .96 can be substantially different than the current development version. This isn't unusual for such a young project, and since the documentation is quite clear and useful it's not a problem, but is something you may want to consider before you plunk down your hard-earned cash on a printed book.
Everytime a new framework or web development system gets hyped I can't but wonder why people get so excited about having reinvented the wheel, and a wonky one at that.
Everything you mentioned in your post has been solved for many, many years already. Just use Perl and the Template Toolkit. Or one of the mature frameworks (Catalyst, Mason) if you hang that way.
It is fast, stable and mature and gets the job done with little development time. Sure, it isn't the latest hype. But do you care? Should you care? If you want to get things done, use Perl.
Books about programming, especially internet programming, seem a bit archaic at this point. Or at least physical books. I find that especially with open source languages and tools, and even more so those related to the web, there is a wealth of information online, both in serial book format, tutorials, and searchable references. I haven't used a book to learn a language since Learning Perl back in about 2000. I bought a copy but I ended up using a pirated digital copy anyway because it was more useful...
LS
There is a fine line between being a cultivated citizen and being someone else's crop. - A. J. Patrick Liszkie
in a flabbergasting coincidence that will leave you all wondering about Fate, i just received my copy of this book today, and was at this very minute beginning to read it. my life has just been slashdotted.
~~~ Paf. Le chien.
We're running Django for basically our entire business systems. It's great. The only downside to Python is that there is a general lack of local developers (Tampa, Florida). Trying to find additional developers when you can't get relocation benefits approved is a royal PITA. (Anyone looking for a job in Tampa? =))
We're very, very happy with Django.
Note that Django 1.0 is due this fall and it looks to be actually on track. I used Zope for personal and freelance projects for about 9 years and professionally for about 2. I migrated my site and the majority of the content over in about a week, and that included the process of learning django.
I will note that one of the things I liked about Zope was the admin interface, which was clunky and minimal but a far sight better than what most other app servers had at the time (late 90's/early 00's). Django's is immensely better.
I've also Read The Fine Book reviewed here and concur with the reviewer. This book is a great introduction to a useful tool.
this is getting old and so are you
blog
I'm about to start a mid-sized project that I'd like to use a framework for. I'm planning on using the Zend Framework, since I know PHP very well. I do not know Python, but it's very high on my list of languages I'd like to learn (like, number 1).
Would it be worth my time to learn Python and then do the project in Django? I'm experienced enough in OO and various languages that I don't think Python would take me too long to pick up, but is the learning curve between knowing Python and using Django steep enough that it cancels out the benefits of using Django over Zend (if there even are any in the first place)?
pylint. It has some annoying style checks that I often disable, but is good at finding unused and undeclared variables and that sort of stuff.
Dewey, what part of this looks like authorities should be involved?
I have some experience using mod_perl & Django in mod_python. Django provides much that perl does not, and I love writing perl for backend utilities and CGI.
Django templates do not allow the scriptlet mentality of others like JSP & mod_perl. They have a short list of commands, a loop, an IF-statement, and some text filters. This forces users to separate computation (in perl/python code) from display (in the template). The template takes a dictionary of named (keyed ) objects and prints the fields.
Django has an Object-Relational Model built-in to the system. Programmers write a models.py module full of ORM classes. Then, the Django utilities build SQL database tables to match the models. The Django Object-Relational Model has no equal so far as I've seen.
Django enforces the MVC web application. Most other web frameworks let the bad habits creep in.
After a loooong time, 1.0 Alpha was just released.
Web2.0: I love when people Flickr my cuil and digg my boingboing until my google is reddit and I start to yahoo
there are tools like pychecker, they help quite a bit. junit is right there in the standard library of python, see docs for the unittest module; there's also the doctest module for simple cases.
I just started messing around with python and I am impressed with how easy it is to get started. I looked over Django a couple of times and was just clueless. Is Django just a backend framework? Do all the frontend UIs need to be done in html/xhtml? I couldn't see anything in the documentation about assisting with UI design. Thanks
"If you like Battlestar Galactica, you're probably a huge nerd." -Stephen Colbert
The Google App Engine already has the Django libraries available.
Have a little care, there. The GAE caused quite a stir in the Django community, because it is only a partial implementation of the database interface that Django normally uses. It is backed by BigTable, which is blazing fast, but not a full blown relational database. If that works for you, go for it - it looks like a sweet platform for certain kinds of projects.
As for your question about Java->Python, I'm a former C++ convert myself, but I can help a little here. For some 'compile time' checking, look at PyLint It may check too much for you, but you can turn off the stuff you don't want.
As for unit testing, PyUnit is a pretty straight port of JUnit, so that should look familiar. However, I actually find nose to be a little better. It has many of the same capabilities, but with less boilerplate needed, and it integrates well with any existing PyUnit or DocTest tests.
-V-
Who can decide a priori? Nobody.
-Sartre
Python objects are dynamic the way Javascript ones are. It's possible to define a new method, or a field, on an object at any time. The interpreter doesn't know ahead of time the way Java can.
Type errors are one thing you can control. Since a Python variable can contain ANY object type, you may set it to the NULL value for that type you want.
my_dict = {}
my_dict[key] = value
my_string = ''
my_integer = 0
You may pre-define class fields as well. Django requires a models database field to be declared! Use the Python "property" function to calculate other fields withe getter & setter functions.
class Sample:
my_field = 100
my_sqrt = property(get_sqrt, set_sqrt)
def get_sqrt(self): return sqrt(self.my_field)
def set_sqrt(self, value):
self.my_value = value*value
The my_sqrt field is calculated as the square root of the my_field field. You may use the obj.my_sqrt in Django templates easily.
1. Perl is a mess.
2. Rails is a mess.
3. Python isn't a mess.
4. Hopefully one of the emergent frameworks on python won't be a mess ... django isn't ... and it's pretty mature at this point ... and has been for about a year or so ;)
Does this make anybody else think of Dwango?
"Dial-up Wide-Area Network Game Operation"
It came with Doom.
Link
The big advantage of a soft copy of book is being able to do searches for keywords which is invaluable when you don't know which set of terminology the author is using and the index doesn't cover the word or phrase you require.
Note this is particularly invaluable in API references - particularly with php when you have no clue which daft name php uses for a function, but you are sure that php has function for that job.
Just wanted to say thanks for the links and information. I'll be sure to read the Python documentation more, but it's always helpful to get some advice. Cheers.
I got this book last week and it's worth the money!! I was having trouble with custom templates tags. After reading The Definitive Guide, writing filters and include tags were easy but the examples given for custom tags were too complex to start off with. However, when i saw James' examples (latest_entries) it all clicked !!! I've already written some custom tags to generate charts from ChartDirector Also i wish i had read his CMS stuff when i first started django it really shows you how to leverage the flat pages By the way his B-List blog (http://www.blist.org/weblog/categories/django/) also kicks ass!!
All of the features that you list seem to be about limiting the options of the programmers rather than extending the capabilities of the base language.
Any time that I hear that something is going to "force me to do it the right way" I know that the first project I try to use it on will need to do something the wrong way. If a tool provides a great way of doing something then it shouldn't need to force me to use it, I would use it that way naturally.
Intron: the portion of DNA which expresses nothing useful.
Django is a Boss-DJ
Then there is the other half of the internet, doing fancy web 2.0 stuff etc. There the problem of the limited options is that at some point you will need to start to make workarounds, and the whole "clean" software becomes a huge mess. Actually, I just yesterday tried to apply online at a company, but their SAP-Web-Service Registration package was such a mess of different login procedures that I couldn't finish the registration, or even log in again. Or get my password again. Since we are talking multinational company here, I am really amazed why they used such a limiting package for this. And a bad one at that. Message to them and others: If you want to do fancy stuff, please do it yourself with decent, flexible, relatively low-level tools, where it is clear exactly that it is doing what you programmed it to do.
Perl-wise: I wrote my own SQL-based CMS site from scratch in perl, in about 3 days. This included testing several of the CPAN packages for SQL interaction and automated layout.
molmod.com - computing tips from a molecular modeling
Django Reinis one of the most influential jazz guitarists of all time. Lived in Europe in the 1930s-40s, played with two fingers on one hand because he was burned in a fire. See Wikipedia, though it's tough to appreciate him without hearing it live. The Modern Jazz Quartet's best-known tune was titled Django.
'Cause maybe a django ate your baby!
tell the truth, there's very little related to the web that can't be done with RPG III. That's been obsolete for 10 years and runs on AS400's... What's needed on the web is not "more power" but more structure to work quickly, be reusable, and manageable 3 years later. That's why RPG is still used, because you can pick up a 15 year old program and the formating and instructions are so rigid there's little room for interpretation of what the program does. Systems like AS400 became popular because they presented one way to write programs, one screen model, one data entry method, and one pool of data... Things like Ruby on Rails in my opinion are trying to create a new "default" structure in the web world... any structure.. so programmers focus on filling in the boxes/structures with what the end client wants rather than creating "clever" re-inventions for every project.
I think Java has fallen down because there's so many "great" ways to do non-trivial stuff.. and they're so big it takes years to learn one of them properly.. then they make new non-compatible replacements and developers start all over! PHP in some ways already suffers the same problem... too many middleware templates but none widespread enough to call "standard". Ruby on Rails jumps in and grabs the spotlight because it's "done" for no other reason. Somebody put all the pieces together, made the tough calls without asking "permission" and then turned it loose. People may not agree with all of it, but it's ready to start work. Django looks like the same tool set, with more focus on the end page content, for Python, but does it have the code management Rails has?
Devoid of context, yes, I can see that.
In context, however, not so much. Consider Django's built-in template system (which you don't have to use, btw; most people do because it leads to easier interoperability with arbitrary applications, but you're free to drop in whatever you like -- it's just Python code on the backend); most people instinctively get upset when they find out that it isn't just the host programming language embedded into HTML (a la PHP, ERB, "classic" ASP, etc.). But I've found that it's extremely rare for me to have a need for such a thing, and when I do the template system is extensible from the Python side, so I can implement what I need and get on with life. A good example I ran into the other night while helping someone debug: he was doing a product-review site where each product had a government-issued safety rating, from one to five stars. What he wanted was basically a way to say something like:
{% if product.safety_rating > 3 %}This product has a high safety rating.{% endif %}
(the curly-brace constructs are how Django's template language delimits certain constructs, such as conditionals, loop expressions, etc.)
Now, you can't actually do this: arbitrary Python expressions like product.safety_rating > 3 aren't supported by the language. What he ended up doing was moving this logic into a method on the object representing products, so it became if product.has_high_safety_rating instead. For most cases in most applications, this is a better option (it's more reusable, and leads to easier maintenance since you don't have magic numbers hard-coded everywhere). And for times when you need it, you can dip down to the Python level and extend whatever syntax you need into the template system (one night I sat down and implemented a bunch of comparison expressions; it took about five minutes).
The parent comment you're responding to is also slightly incorrect on a few points; for example, Django doesn't "enforce" MVC in any particular way and actually deviates from it in some ways that made sense for the Web (e.g., the concept of the controller really has no place in most web applications, since there's only a single channel for interaction with the app: HTTP). All Django cares about is that for each URL you want to handle, you provide a callable object which accepts an HTTP request as its first argument and returns an HTTP response. Beyond that, the sky's the limit. Django also doesn't force you to use its ORM; several of the bundled applications in django.contrib make use of it (since, if you've got Django installed, they can rely on the ORM being available), but nobody says you have to use it in your apps.
By the time you've finished the third chapter, you've built the foundation of a typical brochureware site, complete with a working search system
And a quote from the author's djangosnippets.org:
Why isn't there a search system?
Because no-one's yet written a good generic search system for Django. When somebody does, I'll look into adding it.
;)
Anyhow, I've been using Django for a bit less than an year now. It really is great, strips away lots of boilerplate code but at the same time is quite extensible for the most part. It can still give you headaches occassionally, but a lot of work has been done on decoupling the components and other enhancments. From what I understand, the new "newforms admin" which has just been merged into the trunk should go a long way to help with extending the back-end interface, though I haven't used it yet. Other things still leave something to be desired, e.g. the permission system is really basic etc.
All in all it's a super product, and the online documentation is one of the best I've ever seen. It's nice to see an addition to it in the form of this book, especially considering that the author is a real Django "insider" and knows what he's talking about
Look at this book:
Pearl Django Play-Along Songbook
By Greg Ruby
Pitty they misspelled "Perl" ;)
The book reviewed sounds OK. I found "Sams Teach Yourself Django in 24 Hours" to be a fast way to get up to speed on Django. Anyone have recommendations for other Django books?
Just to follow up: Python has two flavors of tests -- unittest, which was originally the PyUnit software you've already been pointed to, and doctest which lets you write interactive examples -- and Django's test framework has baked-in support for both of them, along with extension points to plug in your own system if you prefer. There's also a dummy HTTP client which can send requests and inspect the responses being sent back (including verifying data-processing from the backend), and a co-worker of mine has released some software which generates a test suite from a live browser session to ease creation of your tests.
Personally, I've always felt that Python's doctest system is one of the greatest things since sliced bread; for example, it lets us produce a single document which in one context can be processed as API documentation but, in another, is executable as a unit test suite for the features it's documenting.
Django has an Object-Relational Model built-in to the system. Programmers write a models.py module full of ORM classes. Then, the Django utilities build SQL database tables to match the models. The Django Object-Relational Model has no equal so far as I've seen.
Django enforces the MVC web application. Most other web frameworks let the bad habits creep in.
You have just given the exact same list of reasons I chose to use Groovy/Grails over Ruby on Rails. You have peaked my interest. So I will definitely have to take a look at Django. Especially now that there is a Django plugin for Grails: http://www.grails.org/DjangoTemplates+Plugin ... I have a couple of toy projects I may choose to do in Django to get a feel for the framework...
[signature]
Django provides much that perl does not
No, it doesn't. You just don't know perl's tools. For example, the "scriptlet" thing you mention has nothing to do with perl -- it's a feature of some specific framework you chose. Perl's Template Toolkit is very similar to Django templates, and perl has great ORM tools like Rose::DB::Object.