0

I have this model.py:

from google.appengine.ext import db

class Poem(db.Model):
    title = db.StringProperty()
    words = db.StringListProperty()
    created_on = db.DateTimeProperty(auto_now_add = 1)
    created_by = db.UserProperty()

    def __str__(self):
        return str(self.words)

    def get_absolute_url(self):
        return '/poem/%s/' % self.key()

And the following views:

def index(request):
    poems = models.Poem.all().order('-created_on').fetch(20)
    payload = dict(poems = poems)
    return render('index.html', payload)

def create(request):
    if request.method == 'GET': 
        poemform = bforms.PoemForm()

    if request.method == 'POST':
        poemform = bforms.PoemForm(request.POST)
        if poemform.is_valid():
            poem = poemform.save()
            return HttpResponseRedirect(poem.get_absolute_url())

def poem(request, poem_key):
    poem = models.Poem.get(poem_key)
    payload = dict(title = poem.title, words = poem.words)
    return render('poem.html', payload)

When I save a new poem via a creation form, the poem gets shown in the sidebar, among the recent poems, and among all poems on the index page. However, when I click one of the links, neither title nor words seem to have been filled into the template.

4

1 回答 1

0

我找到了答案......我将单独的标题和单词传递给模板,它只需要一首诗。

于 2012-06-30T23:55:41.383 回答