2016-02-05 65 views
0

https://github.com/evernote/evernote-sdk-python/blob/master/sample/django/evernote_oauth_sample/templates/oauth/callback.html如何显示每个Evernote的笔记的内容在Django

https://github.com/evernote/evernote-sdk-python/blob/master/sample/django/oauth/views.py

显示1说明的内容(作品):

// views.py(我的叉子)

updated_filter = NoteFilter(order=NoteSortOrder.UPDATED) 
updated_filter.notebookGuid = notebooks[0].guid 
offset = 0 
max_notes = 1000 
result_spec = NotesMetadataResultSpec(includeTitle=True) 
result_list = note_store.findNotesMetadata(auth_token, updated_filter, offset, max_notes, result_spec) 

note_guid = result_list.notes[0].guid 
content = note_store.getNoteContent(auth_token, note_store.getNote(note_guid, True, False, False, False).guid) 
return render_to_response('oauth/callback.html', {'notebooks': notebooks, 'result_list': result_list, 'content': content}) 

//的OAuth/callback.html(我的叉)

<ul> 
    {% for note in result_list.notes %} 
    <li><b>{{ note.title }}</b><br>{{ content }}</li> 
    {% endfor %} 

如何显示每张钞票在Django的内容?(这是不成功的尝试之一)

updated_filter = NoteFilter(order=NoteSortOrder.UPDATED) 
    updated_filter.notebookGuid = notebooks[0].guid 
    offset = 0 
    max_notes = 1000 
    result_spec = NotesMetadataResultSpec(includeTitle=True) 
    result_list = note_store.findNotesMetadata(auth_token, updated_filter, offset, max_notes, result_spec) 

    contents = [] 
    for note in result_list.notes: 
     content = note_store.getNoteContent(auth_token, note_store.getNote(note.guid, True, False, False, False).guid) 
     contents.append(content) 

return render_to_response('oauth/callback.html', {'notebooks': notebooks, 'result_list': result_list, 'contents': contents}) 

<ul> 
    {% for note in result_list.notes %} 
     {% for content in contents %} 
     <li><b>{{ note.title }}</b><br>{{ content }}</li> 
    {% endfor %} 
</ul> 

回答

1

你应该使用一些数据结构中的每个音符的内容联系起来(假设没有是相同的):

title_contents = {} 
for note in result_list.notes: 
    content = note_store.getNoteContent(auth_token, 
             note_store.getNote(note.guid, 
             True,False, False, False).guid) 
    title_contents[note.title] = content 

return render_to_response('oauth/callback.html', {'notebooks': notebooks, 
                'result_list': result_list, 
                'title_contents': title_contents}) 

在您的模板中:

<ul> 
    {% for title, content in title_contents.items %} 
    <li><b>{{ title }}</b><br>{{ content }}</li> 
    {% endfor %} 
</ul> 
+1

'{%为标题,内容为title_contents.items%}' 固定变量名称,title_contents代替tield_contents – lvcpp

+0

尚王,感谢您的大力帮助! – lvcpp

+0

我修正了错字。不用谢。 –

相关问题