Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8129045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:08:32+00:00 2026-06-06T08:08:32+00:00

As a learning project, I’m using MongoDB with Bottle for a web service. What

  • 0

As a learning project, I’m using MongoDB with Bottle for a web service. What I want to do is fetch results from MongoDB and display them in a template. Here’s the output I want from my template:

output.tpl
<html><body>
%for record in records:
   <li>{{record.city}} {{record.date}}
%end
</body></html>

I can pull the data out no problem:

result = db.records.find(query).limit(3)
return template('records_template', records=result)

But this resulted in no output at all – some debugging shows me that result is some sort of cursor:

<pymongo.cursor.Cursor object at 0x1560dd0>

So I attempted to convert this in to something that the template would like:

result = db.records.find(query).limit(3)
viewmodel=[]
for row in result:
  l = dict()
  for column in row:
    l[str(column)]=row[column]
  viewmodel.append(l)
return template('records_template', records=viewmodel)

Debugging shows me that my view data looks OK:

[{'_id': ObjectId('4fe3dfbc62933a0338000001'),
  'city': u'CityName',
  'date': u'Thursday June 21, 2012'},
 {'_id': ObjectId('4fe3dfbd62933a0338000088')
  'city': u'CityName',
  'date': u'Thursday June 21, 2012'},
 {'_id': ObjectId('4fe3dfbd62933a0338000089')
  'city': u'CityName',
  'date': u'Thursday June 21, 2012'}]

But this is the response I’m getting. Any ideas why?

AttributeError(“‘dict’ object has no attribute ‘city'”,)

Edit: I added that bit about l[str(column)]=row[column] to convert the dictionary keys to non-unicode strings in case that was the problem, but it doesn’t seem to matter either way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T08:08:35+00:00Added an answer on June 6, 2026 at 8:08 am

    You need to use the dictionary syntax to lookup the properties:

    {{record['city']}} {{record['date']}}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm considering a personal learning project. Using .NET(preferably VB) I want to build a
I'm currently working on a semantic web e-learning project. I've made an ontology and
I'm using MapXtreme 2008 v7 for a learning project, and was wondering is there
As a learning project I'm attempting to re-create the procedurally generated hills from Tiny
Hey, I received an learning project from my brother that includes: Create a Drupal
ok, this learning project will run only localy winxp + service pack 3 xampp
I want to write a module in python (This is the learning project) to
I have started working on a Web java learning project. I am making a
As a learning project, I am using django-nonrel with the GAE to design a
Currently Learning Web project in Java. I have a doubt related to it. Actually

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.