Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
Rendering fields manually and custom css class

I am trying to manually render the form fields.

I would like to add a bootstrap and custom css class to rendered html.

How can I do this ?

forms.py

class OrderCreateForm(forms.ModelForm):

    class Meta:
        model = Order

        fields = ['name','postal_code']
        widgets = {
            'postal_code': forms.RadioSelect(),
        }

file.html

 <form action="." method="post" class="order-form">    
 <div class="fieldWrapper">
    {{ form.postal_code }}
 </div>
 <p><input type="submit" value="Send"></p>
    {% csrf_token %}
 </form>
{% endblock %}

rendered html

 <div class="fieldWrapper">
    <ul id="id_postal_code">
    <li><label for="id_postal_code_0"><input type="radio" name="postal_code" value="Yes" required id="id_postal_code_0" />Yes</label></li>
    <li><label for="id_postal_code_1"><input type="radio" name="postal_code" value="No" required id="id_postal_code_1" />No</label></li>
    </ul>
 </div>

How to solve a problem ?

I would appreciate your help.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can add css classes to form fields in the following way:

    'postal_code': forms.RadioSelect(attrs={"class": "form-control"}),

Another option is to not render the form this way at all, and just write your own html.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!