2

I want to add space after "Mobile No: ",meaning in between label and text area. But by using django ModelForms I am not able to do that, it shows "Mobile No:" without any space between label and textarea.

This is how I have described it in models.py file.

phone = models.CharField(max_length=10, verbose_name="Mobile No", validators=[mobileno])

forms.py file

class UserInfoForm(forms.ModelForm):
    class Meta:
        model = UserInfo
        fields = ('phone',)

This is the content of my html file.

<form method="post">    
    {% csrf_token %}
    {{ form }}
       </form>

This is how it is showing by default.

enter image description here

How can I add space between label and textarea. Thanks for you help.

Anurag Sinha
  • 187
  • 4
  • 15

3 Answers3

2

You should iterate through your form fields.

Like this:

<form method="post" > {% csrf_token %}

        {% for field in form %}

        <div class="form-group">
            <label class="col-sm-4 control-label" for="{{ field.name }}">{{ field.label }} : </label>

            <div class="col-sm-8">
                {{ field }}
            </div>
        </div>

        {% endfor %}
    </div>
Prakhar Trivedi
  • 8,218
  • 3
  • 28
  • 35
2

The layout and spacing of form labels and fields is a presentation matter and best handled through CSS.

See also: CSS styling in Django forms

Community
  • 1
  • 1
Dwight Gunning
  • 2,485
  • 25
  • 39
0

At least in 3.1.4 you have the option to use label='Mobile No' and label_suffix=': ' to edit forms.

Rysicin
  • 95
  • 1
  • 10