Home

Hello. My name is Noemi Millman, and Triopter is my web development agency. We handcraft beautiful, dynamic websites.

See what I can do for you.

Noemi Millman: Triopter: Adventures in Django - Comments and more

Adventures in Django – Comments and more

I was home sick from work today, so once I felt well enough to crawl out of bed and sit in front of the computer, I decided to catch up a bit more on my Django.

Quick-n-Easy Comments

First thing I did was to replace the commenting system I’d created for my blog-app-in-progress with the commenting framework that comes for “free” with Django.  It’s not as fully featured as I might like, but it’s got some pretty nifty options, and is fairly easy to set up.  I figured I’d rather know how to use this than re-implement comments any time I want to add them to an app.

There are some interesting ways to extend the functionality of Django’s comment framework, although I don’t really like that they require editing the original source of that framework — especially since Django itself is likely to require upgrading frequently in the near future as we approach v.1.0.  Hopefully either the comments framework will be expanded further, or the model inheritance branch of Django that I’ve heard rumors of will eventually make that much less of an issue.

Absolute URLs

One thing I discovered was that the comments framework requires that the get_absolute_url() method be defined for any class that takes comments, so I took this opportunity to replace all the paths in my app with get_absolute_url() calls.  Except for the paths in the date-based generic templates, since a date object doesn’t have an absolute URL method.

I ended up adding some more global variables to settings.py, and constructing all the URLs from those, including the ones in urls.py and in the get_absolute_url() methods.  This should make future changes to path structure much simpler.

Templates

Lastly, I wrapped everything in the blog in the base template (after troubleshooting a problem with context not passed from a custom view to a custom tag), added a template tag so I could include a date-based archive menu in the sidebar, and set up some very basic design elements in a stylesheet in the header, to visually separate the sidebars from the content (I think this will make development a bit more pleasant).

All in all, not bad for another 4 hours or so of work in an unfamiliar language and framework.  I’m very pleased with how easy it is to develop in Django, although I’m still extremely frustrated at times with documentation that fails badly to describe syntax (I’m not talking about Python syntax only, but also which optional function arguments should or shouldn’t be in a dict; or syntax for Django’s template language).

I’m also pleased that I’m feeling better.  I might even venture to add chicken soup back into my diet tonight!

Post a Comment

Your email is never published nor shared. Required fields are marked *

Comments may be held for moderation to prevent spam: your comment may not appear immediately.