[Django]-How to place a the label/description of a django char field above the textbox

4👍

Actually, I have found an easy way to do this without touching the css files (which I shouldn’t do in this particular project). Just add a 100% width attribute to the text field and it will fill up whatever

/ or whatever it is part of which will automatically place the text on top of the text field.

introduction_text = forms.CharField(widget=forms.Textarea(attrs={'style': "width:100%;"}))

0👍

By adding help in .py field you can make label/description above the text box.

Like this -> introduction_text = forms.CharField(widget=forms.Textarea,help='You can add description here')

-1👍

Wrapping the text with a div will let textarea to come on a new line. Since div is a block element.

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

      <input type="submit" value="Submit">
  </form>
</div>

Leave a comment