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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:41:40+00:00 2026-05-27T16:41:40+00:00

I have a a form that I want to output as custom HTML. My

  • 0

I have a a form that I want to output as custom HTML. My forms.py:

from django import forms

from cdrs.models import Localitymayor

class SearchForm(forms.Form):
    genus = forms.CharField(max_length=100)
    species = forms.CharField(max_length=100)
    island_group = forms.ModelChoiceField(queryset=Locality.objects.values_list('islandgroup', flat=True).distinct('islandgroup').exclude(islandgroup="n/a").order_by('islandgroup'))
    island_name = forms.ModelChoiceField(queryset=Locality.objects.values_list('islandname', flat=True).distinct('islandname').exclude(islandname="n/a").order_by('islandname'))

In the Django documentation it demonstrates how to output custom html. However the template code below obviously doesn’t work for the select fields:

<form action="/search/" method="post">
{{ form.non_field_errors }}
<div class="fieldWrapper">
    {{ form.genus.errors }}
    <label for="id_genus">Genus:</label>
    {{ form.genus }}
</div>
...
<div class="fieldWrapper">
    {{ form.island_group.errors }}
    <label for="id_island_group">Island Group:</label>
    {{ form.island_group }}
</div>
...
</form>

How do I control the output of select fields for my ModelChoiceFields?

  • 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-27T16:41:41+00:00Added an answer on May 27, 2026 at 4:41 pm

    In order to change how Django renders list items you need to override that field’s widget.

    See the Customizing widget instances in the documentation.

    And Overriding the default field types or widgets.

    Finally, if this doesn’t give you enough control, you can write your own custom widget. Here is an example of a custom widget for working with key-value pairs. However, the only part you should be concerned with is the render() method. You could extend a built in list widget, override the render() method and make it spit out the html you want.

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

Sidebar

Related Questions

I have a form that I want to be validated before showing it initially.
I have a form that i want to appear at the top of every
I have a form that i want an administrator to fill out, then click
I have a form that i want to auto populate the last 2 fields
Okay all, I have a form that I want users to fill out. When
I have a small form that I want to have people fill out on
I want to have a Form that can Add or Delete TextFields. I was
I have a form that validates the email address and I want to be
I have XML in the following form that I want to parse with PHP
I have this select input in my form that I want to access via

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.