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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:11:01+00:00 2026-05-13T13:11:01+00:00

I’m wrestling with how to best create HTML pages in Django that can either

  • 0

I’m wrestling with how to best create HTML pages in Django that can either be used for displaying or editing data. That is, I’d like the field’s values to appear as text in display mode, but in their widgets when in edit/add mode. It appears that Django wasn’t designed to do this: the fields always appear in their widgets (eg, text input, text area,
etc).

Is there a common technique for handling this, short of using forms for one, and not the other?

I was thinking of a custom templatetag filter that could be used for every form field, like:

{{ form.field_name|render_field:mode }}

where render_field would either return the field’s HTML widget, or just the value as text, based on the mode.

Have I missed something, or is this a viable solution?

  • 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-13T13:11:02+00:00Added an answer on May 13, 2026 at 1:11 pm

    Answering my own question, apparently. I ended up with a three-part solution:

    1. attach the model to the form, so I’ll have the default display widgets for each field
    2. write the form using a template tag, passing it the form.field, user, and action
    3. write a render template tag to handle #2

    Step one:

    form.model = Model(...)
    

    Step two:

    
     {{form.field1.label}}
     {% render form.field1 user action %}
    
    
     {{form.field2.label}}
     {% render form.field2 user action %}
    
    

    Step three:

    Something like:

    def render(formfield, user, action, default_text="Private"):
        if not user.is_authenticated():
            action = "view"
        if action == "view":
            if user.is_authenticated():
                fieldname = formfield.name 
                retval = str(getattr(formfield.form.model, fieldname))
            else:
                retval = default_text
        else:
            retval = formfield.as_widget()
        return retval
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small

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.