This is an excellent interview with Adrian Holovaty, covering his work with Django, Python, and how he got involved in this dual-discipline of computer science/journalism.
« Into The Future Into The Past »
All Items Tagged With “python” (Subscribe to this tag)
Chatting with Adrian Holovaty
Link bookmarked via Diigo on Tuesday, January 1, 2008 @ 09:29 CST by Daniel Andrlik
Two-Faced Django Part 1: Building a project that exists simultaniously on Facebook and the web
Link bookmarked via Diigo on Friday, December 14, 2007 @ 11:12 CST by Daniel Andrlik
Via Simon Willison
Will Larson has prepared a really excellent tutorial on building a Django application that will have both a web app and a Facebook app component to its interface.
Send Django Exceptions to DPaste
Link bookmarked via Diigo on Sunday, December 9, 2007 @ 13:13 CST by Daniel Andrlik
Michael Trier points out a cool new feature in Django that is awesome for debugging. On Django error pages (with DEBUG turned on) there is now a button that will automatically post the contents to dpaste. Very nice, indeed.
xkcd - Python
Link bookmarked via Diigo on Wednesday, December 5, 2007 @ 07:58 CST by Daniel Andrlik
This comic pretty much sums up why I love programming in Python. Well that and the title tag for the comic, which reads, “I wrote 20 short programs in Python yesterday. It was wonderful. Perl, I’m leaving you.”
Unfortunately, the module for antigravity isn’t in the standard library yet, so he must be using a third-party module.
The B-List: Newforms, part 1
Link bookmarked via Diigo on Friday, November 23, 2007 @ 08:04 CST by Daniel Andrlik
If only this article had been written and posted when I was first building my personal site. It would have saved me so much time reading this rather than learning how to do this by reading the newforms tests.
Reinteract - Better interactive Python « fishsoup
Link bookmarked via Diigo on Monday, November 12, 2007 @ 08:36 CST by Daniel Andrlik
I really like this idea for an interactive python shell that also allows inline edits. Looks like this is just for a gtk interface at this point, and I mostly just use shell at the command line, but this is certainly a compelling and convenient feature.
Yaaar
Blog Entry posted on Wednesday, September 19, 2007 @ 00:05 CDT by Daniel Andrlik
Ahoy, mateys! Today be the official Talk Like A Pirate Day and the Ministry o’ Intrigue will be celebrating by servin’ up all me text as pirate speak fer the duration.
This be accomplished by activatin’ a piece o’ Django middleware as suggested in thar Django Master Class and I be using the pirate filter ported to Python by the swashbucklin’ Jacob Kaplan-Moss.
So go and celebrate proper or ye’ll be keelhauled or at least made to walk the plank!
UPDATE: Well that was fun.
Now the holiday is over, so I’m turning the middleware off.
Fun With Django Feeds
Blog Entry posted on Friday, August 3, 2007 @ 02:04 CDT by Daniel Andrlik
I would like to take a moment to show you how easy it is to create feeds in Django, and the easiest way to do that is by example. For brevity’s sake, I’m going to use a simplified version of a Django-powered blog. So, let’s say you have a simple blog, where posts consist of a title, slug, pub_date, body and some tags. So your model would look something like this:
blog/models.py
from django.db import models
from tag.fields import TagField
from datetime import datetime
class Entry(models.Model):
title = models.CharField(maxlength=250)
slug = models.SlugField(
maxlength=250,
prepopulate_from=('title'),
unique_for_date='pub_date'
)
body = models.TextField()
pub_date = models.DateTimeField(default=datetime.now())
is_draft = models.BooleanField(default=True)
allow_comments = models.BooleanField(default=True)
tags = TagField()
def __unicode__(self):
return self.title
def get_absolute_url(self):
#You would fill this in here and call it when you need it or
#use the permalink decorator
#Regardless, you want to customize it for your urls.py
pass
Now, I’m assuming you already know something about the Django ORM, but I’ll summarize for those of you that don’t. Essentially, we are creating an object of type Entry, which represents a table in your database and has the attributes I listed above. I’ve added a few constraints, such as requiring the slug field to be unique for a given date, since in most cases you will probably build a permalink along the lines of /year/month/day/slug. I’ve also cheated and added two boolean fields which designate if the entry is a draft, and if it allows comments, because they are too useful to leave out, even in an example. TagField is supplied by the django-tagging app, and doesn’t really affect the rest of this example, but I love it so I’m going to leave it in.
Okay, so you’ve got your model and you have used it to load up some entries, and now it suddenly occurs to you: What’s a blog without a subscription feed? The answer to that question is: Probably not worth the effort to remember visiting on a regular basis. You need an RSS feed! Luckily for you, Django makes this dead simple.
So, the first order of business is to define a feed class to represent your data. Unless you have very complex needs, this is very simple because you just have to subclass the Feed class in Django. You’ll have to define a few variables and then tell the feed what items it should be displaying and what date is the representative pubdate. So, a simple example might look like this:
feeds.py
from django.contrib.syndication.feeds import Feed
from blog.models import Entry
class BlogFeed(Feed):
'''Feed for latest 15 blog entries'''
#These could also be pulled from your settings.py file to avoid repetitive hardcoding
title='My Blog'
link='http://www.example.com' #URI of site
description='Latest Blog Entries'
item_author_name='Joe Blow'
item_author_email='joe@example.com'
item_author_link='http://www.example.com' #URI of author
def items(self):
#What items to use in the feed
return Entry.objects.filter(is_draft=False).order_by('-pub_date')[:15]
def item_pubdate(self,item):
#For each item, what is the pubdate?
return item.pub_date
So, that’s a simple feed. Now you need to assign this feed to a url, which you do by adding it to your urls.py file. I’m going to just include the feed urls line rather than including an entire site description.
urls.py
from django.conf.urls.defaults import *
from feeds import *
#Here you add a dictionary of feeds with a slug you want them to correspond to
site_feeds = {
'blog':BlogFeed
}
urlpatterns = patterns('',
#Lots of patterns omitted here
(r'^feeds/(?P< url >.*)/$', 'django.contrib.syndication.views.feed',{'feed_dict':site_feeds}),
)
This tells Django that for every time it encounters a request beginning with feeds, it should take the remainder of the url as a slug and find the corresponding feed class in site_feeds. There is only one step left, making the templates. Don’t worry, this is the easiest part.
Every feed needs two templates, although you can reuse templates by specifying the title_template and description_template in your feed class. Otherwise, Django will look for templates that match your feed’s slug identifier in the templates/feeds directory, where templates is your base directory for templates. In this case it will be looking for blog_title.html and blog_description.html. Both templates get passed one variable: obj, which represents a single item in the feed. Both are ridculously simple:
blog_title.html
{{ obj.title }}
blog_description.html
{{ obj.body }}
They are really that simple. You can, of course, apply all your favorite Django template filters or add extra formatting if you wish. If you want to include any other information that you might pull via template tags, you can use those as well. For example if you wanted to also include a comment count your description template would look like this:
blog_description.html
{% load comments %}
{% get_comment_count for blog.entry obj.id as comment_count %}
{{ obj.body }}
{{ comment_count }} comment{{ comment_count|pluralize }} on this entry.
By default, Django will serve up your feed as RSS 2.0, however, you can also create Atom feeds just as easily. You can even serve up both types of feeds by subclassing your BlogFeed class like so:
feeds.py
from django.contrib.syndication.feeds import Feed
from blog.models import Entry
from django.utils.feedgenerator import Atom1Feed
#For brevity's sake, I'm omitting the BlogFeed I described above.
class AtomBlogFeed(BlogFeed):
feed_type = Atom1Feed
subtitle = BlogFeed.description
That’s all there is to it! Simply assign it a feed slug and either create new templates or specify in the AtomBlogFeed class to use the same templates as BlogFeed.
It is possible to completely customize your feeds, but that’s a little out of the scope of this post. This basic approach should work for the majority of cases, and if you need to do something more advanced with your feed, take a moment to browse through the official documentation as there are a wealth of options available to you.
This may initially look like a lot of work, but believe me this takes no time at all. This site generates feeds for every kind of content, including by tag, and tag per category, and I was able to write all of those feeds and have them being served up in about twenty minutes. For a simple example like I am showing here you can be up with feeds in less than ten!
Django makes feed generation quick and easy, and like most aspects of Django, is a joy to work with. Go ahead, take a moment and play with it. If you need an app to work with, you can either flesh out this example or you can go through the official tutorial. Afterwards, I’m pretty sure you’ll be hooked.
The Scoop » Blog Archive » Django, iCal and vObject
Link bookmarked via Diigo on Thursday, August 2, 2007 @ 00:28 CDT by Daniel Andrlik
This is a cool way of using vObject to have Django output a feed of iCal objects. Very slick.
Django Master Class
Link bookmarked via Diigo on Friday, July 27, 2007 @ 17:52 CDT by Daniel Andrlik
Slides from an awesome Django presentation. If you’re interested in doing anything advanced with Django, you need to read through these.


