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

  • Home
  • SEARCH
  • 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 4001826
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:57:06+00:00 2026-05-20T07:57:06+00:00

So I am an avid user of both ModelForms and the {{form.as_table}} template tag.

  • 0

So I am an avid user of both ModelForms and the {{form.as_table}} template tag. This lets me have a generic form template that I can reuse without knowing my specific fields. Now I’d like to print that same model out exactly like I did for the form, but without the form fields. I have never come across a good way to do this. Anyone know of one?

Here is an example, to be more specific:

model:
class ExampleModel(models.Model):
    info1 = models.TextField()
    info2 = models.TextField()

form:
class ExampleForm(forms.ModelForm):
    class Meta:
        model = ExampleModel

view:
def example_form_view(request):
    form = ExampleForm()
    return render_to_response('form.html', locals(), context_instance=RequestContext(request))

def example_display_view(request):
    model = ExampleModel.objects.get(id=1)
    return render_to_response('model.html', locals(), context_instance=RequestContext(request))

To print out the form, I have a template that has:

<form action="." method="post">
    {% csrf_token %}
    <table>
        {{ form.as_table }}
        <tr>
            <td></td>
            <td><input type='submit' value="submit" /></td>
        </tr> 
    </table>
</form>

And I’d also like to be able to have a generic template that includes this:

<table>
    {{ model.as_table }} 
</table>

and get the same layout as the form one, but without the form. Anyone know of any way to do this?

I apologize if this has been asked before, but I did a search and didn’t find anything. Although I wasn’t sure what to search for.

  • 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-20T07:57:07+00:00Added an answer on May 20, 2026 at 7:57 am

    You could define an as_table method on your model (or a superclass if you want to reuse it in multiple models) such as:

    def as_table(self):
        output = '<table>'
        # for each field in model
        for field in self._meta.fields:
            # optionally skip any unwanted fields such as primary keys, etc
            # if field.auto_created:
            #    continue
            output += '<tr><th>%s</th><td>%s</td></tr>' % (
                field.name, getattr(self, field.name))
        output += '</table>'
        return output
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been an avid TFS user since 2005 but decided to skip the
I'm an avid vim user and have started to write some SQL code recently.
I'm an avid Emacs user and love shell-mode that in my opinion brings the
G'day everybody, As an avid firefox user, I use plugins like stylish and Greasemonkey
I am an avid user of the YUI framework ( http://developer.yahoo.com/yui/ ). It has
We are avid Eclipse fans -- it is fantastic! But we have about 40
I have been an avid fan of lazy loading but yesterday I was talking
I am an avid TextExpander for Mac user. I use it to expand code
I have a filemanager application that allows users to upload files to the server
This has been getting on my nerves quite a bit because I can't find

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.