Coder’s Eye

A site about one of the three passions in my life.

Coder’s Eye header image 2

Speedy Django Development

July 7th, 2006 · 3 Comments

GuitarAs I’ve mentioned before, I am building my own web store using Django. The coding is going extremely quickly, thanks to the excellence of the framework.

I find myself marvelling at how quickly and simply various elements come together, especially when I contrast this to my previous experience doing the same thing with Java for an employer.

For example, the Login/User framework. With Django, I simply include the auth middleware, and create a couple templates to “skin” the login, profile, password change, and password reset pages. In return, I get a full-featured, working login system with sessions, cookies, and all that tedious plumbing done for me. Total time from decision to use the built-in framework to implementation? Two hours, including learning the system. Unbelievable.

Contrast that with my use of Acegi/Spring to handle authentication in a Java app. I was shockingly fast implementing this, taking just two full working days. The documentation directly states that you should plan on at the very least one full week. The system was huge, slow, and baroque. Modifying the system was clumsy and frequently required I relearn things from the reams of documentation. Yes, overall it offered more functionality. No, there was no stripped-path to just get the most needed set of features for a website. The craziest thing is that the config files for Acegi
alone were larger than all the code and templates I wrote for django login
.

Another example is my need to generate thumbnails for some graphics. I want to generate them “on the fly”, when needed. Total lines of code to do this in Python with PIL, integrated with Django? 7. Total time? 15 minutes, including all the logic needed to make sure that I only create the thumbnail once.

Contrast this with the nightmare that is the Java image API. I seriously spent days making a caching thumbnailing system in Java for an Auction site I worked on. Even after that, it was much slower than my Python solution.

Now that I am actually developing a serious app for Django, I find myself feeling the love more and more. Thanks Django team!

Technorati Tags: , , , ,

Tags: Languages · Django · Python · Java

Bookmark this article

del.icio.us:Speedy Django Development digg:Speedy Django Development spurl:Speedy Django Development wists:Speedy Django Development simpy:Speedy Django Development newsvine:Speedy Django Development blinklist:Speedy Django Development furl:Speedy Django Development reddit:Speedy Django Development fark:Speedy Django Development blogmarks:Speedy Django Development Y!:Speedy Django Development smarking:Speedy Django Development magnolia:Speedy Django Development segnalo:Speedy Django Development gifttagging:Speedy Django Development

3 responses so far ↓

  • 1 Chris Moffitt // Jul 10, 2006 at 5:42 am

    It’s great to see you’re working on a Django based store. We have a project called Satchmo that is attempting to build a Django-based framework for use in online stores.

    Come check us out here - http://satchmo.python-hosting.com/wiki

    We’re in the very early stages and would welcome any help. However, it is amazing how quick and powerful Django is. for instance, I’ve incorporated Nesh’s thumbnails into the store and it is really easy to create thumbnails and automatically cache them. Or, maybe you can use some of the models/code we’ve put together to help make your transition even easier!

    Thanks,
    Chris

  • 2 Alessandro Ronchi // Feb 27, 2007 at 8:29 am

    Can you out your 7 lines of code to use thumbnails? I have to do the same thing, and it would very useful for me.

    If an image is removed, is the thumbnail removed too?

  • 3 Bruce // Feb 27, 2007 at 9:09 am

    Alright. I have added a few lines since I wrote the blog entry. Here’s the somewhat more developed private method from the class which does that. If you strip the logs and comments, it is 13 lines.

    
    def _create_thumb(self, force):
            log.debug("Thumbnailing (%i x %i) %s", self.x, self.y, self.parent.filename)
            do_create = True
    
            if files.is_file(self.filename):
                if force:
                    log.debug("Forcing removal of existing thumbnail: %s" % self.filename)
                    os.remove(self.filename)
    
                elif files.newest_filename(self.parent.filename, self.filename) == self.parent.filename:
                    log.debug("Found existing (older than parent image) thumbnail, removing: %s", self.filename)
                    os.remove(self.filename)
    
                else:
                    log.debug("Found existing thumbnail, skipping create: %s", self.filename)
                    do_create = False
    
            if do_create:
                im = Image.open(self.parent.filename)
                im.thumbnail((self.x, self.y), Image.ANTIALIAS)
                im.save(self.filename, "JPEG")
                log.debug("Created thumbnail: %s", self.filename)
    

Leave a Comment