Launched Morris Lum's Photography Website
I just recently helping a friend launch his photography website, done entirely in Django 1.1.
I’m pretty impressed by how much Django has improved since the 0.96 days. The best new feature IMO is the addition of annotate and aggregate in the db models. (see documentation)
The forms (previously known as newforms), generic views, and automatic admin makes developing new websites a breeze.
My biggest gripe with Django is still the template engine. With more advanced template engines available for Python (Mako, Jinja2, Genshi), it would be nice if Django is able to support those nicely. You could technically write your own render_to_response function that uses, say Jinja2, but then you’re still stuck with Django’s template engine for admin and generic views. Oh well.
Why use another engine? Not because they’re faster (I highly doubt your bottleneck is template rendering), but because they have more advanced feature sets. With Django, there are cases where I’m forced to not adhere to the DRY philosphy. For example, if I want to define a block of text/HTML in a child template and have it applied to more than one location in the parent. In Mako I can use a <%def > block, and in Jinja2 I can use {% macro %}. In Django, I’d have to define two or more {% block %}s with the exact same content. Yes, it could technically be done in the views, but it may not be possible if you’re using generic views, and sometimes it just doesn’t make sense when you’re not dealing with data from models.
And I also wish Django had a Pylons’ interactive debugger. That thing is genius!
All in all, I still love the Django pony. Like I said, it makes website development a breeze.
Playing around with Pylons
I started playing with a Python web framework called Pylons. I’ve been using Django for the last little while, but after hearing many positive feedback about the Pylons, so I decided it’s time to get my hands dirty.
Although I’ve barely scratched the surface of Pylons, but here are some things I like about it.
- I love Python Paste. Deploying and dispatching your web app suddenly becomes very easy. You can even register your application at PyPi.
- The default Mako templating engine is very, very fast. It has a newline filter (backslash) to consume the newline character before moving to the next line – which is useful if you want nicely formatted HTML. Comments can be multi-lined – something I wish was possible in Django. And it’s also nice to have arbitrary Python code embedded in the page… should be used sparingly, but really useful sometimes.
- SQLAlchemy is powerful. Arguably the best ORM in any language. Doesn’t get in your way when designing your database and application architecture. You can map objects to any arbitrary joins or selects.
- Really gives you full control over your application. Pylons doesn’t give you out-of-the-box admin or user authentication (like Django), but it does allow you to build your application exactly the way you want without having to work around the framework.
Don’t get me wrong. I like Django, and will continue to use it where it makes sense. Forms in Django 1.0 is really awesome, and I especially like ModelForm for creating forms from models. The admin view that comes with Django is great, and saves a lot of development time.
If you do use SQLAlchemy with Pylons, you can always check out formalchemy, which many of the same functionality as Django’s ModelForm, but with SQLAlchemy mapped objects. As a bonus, you can even use a Pylons extension with formalchemy that gives you automagically created admin interface for your objects.
And some more thoughts about Django.
- You can use SQLAlchemy in Django. That is, if you’re willing to give up the built-in admin and generic views, and ModelForms.
- There are ways to get other more powerful Python templating engines into Django (e.g. django-mako), but it does require you do change your view code.
So here are my not-so final thoughts.
I’ll continue to use Django for the many web applications that are basically just CRUD applications. For anything that you need to have fine-grained control over, Pylons seems to be the better choice. It also allows you do use
Hello Interweb! 1
This is my first attempt at a dedicated programming blog. More interesting posts are on their way, but for now here’s a little info about me!
In my short professional career (which includes several co-op jobs when I attended the University of Waterloo) I’ve mostly been in web development. Actually, I’ve been doing the whole web stuff since about mid-90s, starting with HTML, JavaScript and Perl. Just on my personal/hobby websites.
I’ve worked with many languages, but my current interests are JavaScript and Python. I am a huge fan of Django, and have used it on several projects, including GlobeCampus. I expect the majority of my posts in the near-future to be on JavaScript and Python. ;)
Currently, I’m working as a web developer at The Globe and Mail.