Writing Blogging Software for Google App Engine

34 views
Skip to first unread message

Brian Clapper

unread,
Aug 8, 2008, 9:46:20 AM8/8/08
to google-a...@googlegroups.com
I just posted an article on my blog entitled "Writing Blogging Software for
Google App Engine". I recently moved my own (simple) blogging software
from Django to GAE, and the exercise was quite enlightening. I thought it
might be helpful to share the experience.

The article's long, but I welcome feedback from the GAE experts on this
list.

http://brizzled.clapper.org/id/77

Regards,

Brian Clapper, http://www.clapper.org/bmc/
Mankind has yet to devise a rule that never requires exceptions.
-- Wayne Dyer

g-man

unread,
Aug 8, 2008, 11:42:39 PM8/8/08
to Google App Engine
Thanks from all of us learning the subtleties of the App Engine. One
of the best ways to learn programming is to read well-written code,
and I'll be exploring yours, which you so kindly posted (along with a
fine narrative) on your site.

After a cursory look, I have a question and a comment:

My question is: are you live at http://picoblog.appspot.com? I seem to
get a 404 when I visit there. If not, I don't recall seeing
instructions on how to redirect to your private hosting, if that's
what you're running on now.

My comment is: I take it, then, that you chose not to use the
app_engine_helper_for_django, correct? I'm wondering why, since it's
becoming almost seamless to old-school Django, and you use the Django
templating language anyway. As I always say, 'Good enough for Guido is
good enough for me!', and it seems that there will be no more
development of the vanilla App Engine 'webapp' framework, from what
I've read on the group.

I look forward to getting into some deeper philosophical discussions
after I've really looked into your implementation.


On Aug 8, 6:46 am, Brian Clapper <brian.clap...@gmail.com> wrote:
> I just posted an article on my blog entitled "Writing Blogging Software for
> Google App Engine". I recently moved my own (simple) blogging software
> from Django to GAE, and the exercise was quite enlightening. I thought it
> might be helpful to share the experience.
>
> The article's long, but I welcome feedback from the GAE experts on this
> list.
>
> http://brizzled.clapper.org/id/77
>
> Regards,
>
> Brian Clapper,http://www.clapper.org/bmc/

Bill

unread,
Aug 9, 2008, 2:23:32 AM8/9/08
to Google App Engine
Hi Brian,

Congrats on your blog app. There's a bunch of us getting to know
AppEngine
using that route :)

I'm still figuring out the best way to handle Atom feeds if my blog
entries are
HTML. I figure since I'm the one writing those entries, there
shouldn't be
a security issue. Comments, on the other hand, should probably get
escaped.
Anyway, if you use the escape filter (like in your example), it seems
to expose
all the HTML tags in the Atom feed. If you use CDATA, same thing.
Probably should just use the Django feed helpers...

On the tag queries, you can do queries on lists of tags. You can
check out
the TagHandler class of Bloog (bloog.billkatz.com). If your model is
like this:

class Article(db.Model):
tags = db.ListProperty(db.Category)

then you can do this:

db.Query(Article).filter('tags = ', some_tag).order('-published')

The filter documentation describes how queries work against
ListProperty:

http://code.google.com/appengine/docs/datastore/typesandpropertyclasses.html#ListProperty

I'm working on a more advanced form of tag mixin, but it's probably
not needed for
a simple blog.

Best,
Bill

On Aug 8, 6:46 am, Brian Clapper <brian.clap...@gmail.com> wrote:
> I just posted an article on my blog entitled "Writing Blogging Software for
> Google App Engine". I recently moved my own (simple) blogging software
> from Django to GAE, and the exercise was quite enlightening. I thought it
> might be helpful to share the experience.
>
> The article's long, but I welcome feedback from the GAE experts on this
> list.
>
> http://brizzled.clapper.org/id/77
>
> Regards,
>
> Brian Clapper,http://www.clapper.org/bmc/

Brian Clapper

unread,
Aug 9, 2008, 9:58:08 AM8/9/08
to google-a...@googlegroups.com
On 8/8/08 11:42 PM, g-man wrote:
> Thanks from all of us learning the subtleties of the App Engine.

You're welcome. It's only fair, since I've learned a few things reading
this group.

> After a cursory look, I have a question and a comment:
>
> My question is: are you live at http://picoblog.appspot.com? I seem to
> get a 404 when I visit there. If not, I don't recall seeing
> instructions on how to redirect to your private hosting, if that's
> what you're running on now.

I'm not actually running the "picoblog" software. I took the existing
blogging software I'm using at "brizzled.clapper.org" (which is also
"brizzled.appspot.com") and pared it down for the purposes of the blog
article. The actual software I'm using for my blog is very similar to the
picoblog software, but I'm constantly playing with it, and I wanted
something a little simpler (and less in flux) for the purposes of the
article.

However, I did test the picoblog software using dev_appserver.

I'm not running on private hosting, though; my blog is actually running on
Google App Engine. I *was* using Django on a VPS I lease, but I cut over to
GAE last week. I'm sure Google would prefer that I use Blogger, which is
(I'm sure) better tuned for blog traffic. :) But this way, I learn more
about GAE, and I have complete control of the software.

> My comment is: I take it, then, that you chose not to use the
> app_engine_helper_for_django, correct? I'm wondering why, since it's
> becoming almost seamless to old-school Django, and you use the Django
> templating language anyway. As I always say, 'Good enough for Guido is
> good enough for me!', and it seems that there will be no more development
> of the vanilla App Engine 'webapp' framework, from what I've read on the
> group.

I originally ran my blog on Django. In fact, the first time I ported it to
GAE, I used Django on top of GAE. I hadn't heard that the webapp framework
was going away in GAE, and I deliberately chose to convert the blog from
Django to webapp to learn more about webapp and the "raw" GAE code.

If support for webapp is, indeed, going away, it's no big deal to switch
the code back to use Django again.

> I look forward to getting into some deeper philosophical discussions
> after I've really looked into your implementation.

Thanks for the kind comments.

Regards,

Brian Clapper,http://www.clapper.org/bmc/
Why does opportunity always knock at the least opportune moment?

Brian Clapper

unread,
Aug 9, 2008, 9:58:19 AM8/9/08
to google-a...@googlegroups.com
On 8/9/08 2:23 AM, Bill wrote:
> Hi Brian,
>
> Congrats on your blog app. There's a bunch of us getting to know
> AppEngine using that route :)

Yes, it's a small, well-controlled application, suitable for exactly that
purpose.

> I'm still figuring out the best way to handle Atom feeds if my blog
> entries are HTML. I figure since I'm the one writing those entries, there
> shouldn't be a security issue. Comments, on the other hand, should
> probably get escaped. Anyway, if you use the escape filter (like in your
> example), it seems to expose all the HTML tags in the Atom feed. If you
> use CDATA, same thing. Probably should just use the Django feed
> helpers...

I don't mind exposing the HTML tags in the feed. I wrote a (Java) feed
reader awhile back (which I still use on a daily basis and which is posted
to my web site), and as I debugged that thing, I found that people put a
wide variety of stuff in their feeds. It's actually fairly common to see
HTML embedded in an RSS or ATOM feed.

In my case, since I'm storing reStructuredText, I could also write an
RST-to-text converter to produce non-HTML output, if desired.

> On the tag queries, you can do queries on lists of tags. You can check
> out the TagHandler class of Bloog (bloog.billkatz.com). If your model is
> like this:
>
> class Article(db.Model):
> tags = db.ListProperty(db.Category)
>
> then you can do this:
>
> db.Query(Article).filter('tags = ', some_tag).order('-published')
>
> The filter documentation describes how queries work against
> ListProperty:
>
> http://code.google.com/appengine/docs/datastore/typesandpropertyclasses.html#ListProperty
>
> I'm working on a more advanced form of tag mixin, but it's probably not
> needed for a simple blog.

Ah! Excellent. I must have missed that. I'll play with it, update the code,
and update the article (with credit to you for pointing me there). Thanks!

Regards,

-Brian

Brian Clapper, http://www.clapper.org/bmc/
A diplomat is someone who can tell you to go to hell in such a way that you
will look forward to the trip.
-- Caskie Stinnett

Fernando Correia

unread,
Aug 9, 2008, 10:32:34 AM8/9/08
to google-a...@googlegroups.com
Brian, what a fantastic article! Congratulations.

I think I may have a correction for you:

<< A note about the unique ID: Unlike Django, GAE does not provide
support for an automatically incremented integer ID field. Items do
have unique keys, but they're long and ugly. >>

Actually, GAE model objects do have autogenerated integer IDs:

some_object.key().id()

id()

Returns the numeric ID of the data entity, as an integer, or None
if the entity does not have a numeric ID.

http://code.google.com/appengine/docs/datastore/keyclass.html#Key_id

The "ugly" key string is this integer ID encoded and obfuscated:

<< A string-encoded key is an opaque value using characters safe for
including in URLs. The string-encoded key can be converted back to a
Key object by passing it to the Key constructor (the encoded
argument). Note: A string-encoded key can be converted back to the raw
key data. This makes it easy to guess other keys when one is known.
While string-encoded key values are safe to include in URLs, an
application should only do so if key guessability is not an issue. >>

cb

unread,
Aug 10, 2008, 5:39:23 PM8/10/08
to Google App Engine
This article was very helpful.
As a novice Python programmer, this was one of the few simpler
examples that I could.
Thanks again for making it available and providing the source code to
allow us novices something to work with.

On Aug 9, 9:58 am, Brian Clapper <brian.clap...@gmail.com> wrote:
> On 8/8/08 11:42 PM, g-man wrote:
>
> > Thanks from all of us learning the subtleties of the App Engine.
>
> You're welcome. It's only fair, since I've learned a few things reading
> this group.
>
> > After a cursory look, I have a question and a comment:
>
> > My question is: are you live athttp://picoblog.appspot.com?I seem to

Brian Clapper

unread,
Aug 10, 2008, 9:53:34 PM8/10/08
to google-a...@googlegroups.com
On 8/10/08 5:39 PM, cb wrote:
> This article was very helpful.
> As a novice Python programmer, this was one of the few simpler
> examples that I could.
> Thanks again for making it available and providing the source code to
> allow us novices something to work with.

You're welcome, Bob, and thanks for the kind comments. If you improve upon the
source, please drop me an email.

I've just added page caching to my version of the code; I'll probably write an
article about it later this week. (It's straightforward stuff, but writing it
up might save someone some time.)

-Brian

Brian Clapper, http://www.clapper.org/bmc/
Mitchell's Law of Committees:
Any simple problem can be made insoluble if enough meetings are
held to discuss it.

Reply all
Reply to author
Forward
0 new messages