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 3277266
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:20:58+00:00 2026-05-17T19:20:58+00:00

using app engine – yes i know all about django templates and other template

  • 0

using app engine – yes i know all about django templates and other template engines.

Lets say i have a dictionary or a simple object, i dont know its structure and i want to serialize it into html.

so if i had

{'data':{'id':1,'title':'home','address':{'street':'some road','city':'anycity','postal':'somepostal'}}}

want i want is that rendered in some form of readable html using lists or tables;

data:
   id:1
   title:home
   address:
           street: some road
           city: anycity
           postal:somepostal

now i know i can do

for key in dict.items
print dict[key]

but that wont dive into the child values and list each key, value pair when the key/value is a dictionary – ie the address dict.

Is their a module for python that is lightweight/fast that will do this nicely. or does anyone have any simple code they can paste that might do this.

Solution
All the solutions here were useful. pprint is no doubt the more stable means of printing the dictionary, though it falls short of returning anything near html. Though still printable.

I ended up with this for now:

def printitems(dictObj, indent=0):
    p=[]
    p.append('<ul>\n')
    for k,v in dictObj.iteritems():
        if isinstance(v, dict):
            p.append('<li>'+ k+ ':')
            p.append(printitems(v))
            p.append('</li>')
        else:
            p.append('<li>'+ k+ ':'+ v+ '</li>')
    p.append('</ul>\n')
    return '\n'.join(p)

It converts the dict into unordered lists which is ok for now. some css and perhaps a little tweaking should make it readable.

Im going to reward the answer to the person that wrote the above code, i made a couple of small changes as the unordered lists were not nesting. I hope all agree that many of the solutions offered proved useful, But the above code renders a true html representation of a dictionary, even if crude.

  • 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-05-17T19:20:58+00:00Added an answer on May 17, 2026 at 7:20 pm

    The example made by pyfunc could easily be modified to generate simple nested html lists.

    z = {'data':{'id':1,'title':'home','address':{'street':'some road','city':'anycity','postal':'somepostal'}}}
    
    def printItems(dictObj, indent):
        print '  '*indent + '<ul>\n'
        for k,v in dictObj.iteritems():
            if isinstance(v, dict):
                print '  '*indent , '<li>', k, ':', '</li>'
                printItems(v, indent+1)
            else:
                print ' '*indent , '<li>', k, ':', v, '</li>'
        print '  '*indent + '</ul>\n'
    
    printItems(z,0)
    

    Not terribly pretty of course, but somewhere to start maybe. If all you want to do is visualize data, the pprint module really is good enough. You could just use the “pre” tag on the result from pprint and put that on your web page.

    the pprint version would look something like this:

    import pprint
    z = {'data':{'id':1,'title':'home','address':{'street':'some road','city':'anycity','postal':'somepostal'}}}
    
    print '<pre>', pprint.pformat(z), '</pre>'
    

    And the html output look something like this:

    {'data': {'address': {'city': 'anycity',
                          'postal': 'somepostal',
                          'street': 'some road'},
              'id': 1,
              'title': 'home'}}
    

    Which isn’t that pretty, but it at least shows the data in a more structured way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Google App Engine and Django templates. I have a table that I
As the title suggests, I'm using Google App Engine and Django. I have quite
I am working on a Django application on Google app engine (using app engine
I have an AppEngine app that I'm migrating to run in Django, using app-engine-patch
I'm using Google App Engine, Jquery and Django. I want POST data to be
I have a simple Google App Engine app, that I wrote using ordinary strings.
I've been using Pydev/Eclipse to develop Google App Engine (GAE) applications but I've been
I'm using app engine with java, developing in eclipse. Is there a way to
When I call resize on images using app engine, they maintain their aspect ratio
I am trying to write a facebook app using app-engine-patch and pyFacebook. I am

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.