Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display some free text in between Django Form fields

I have a form like the following:

class MyForm(Form):

  #personal data
  firstname = CharField()
  lastname = CharField()

  #education data
  university = CharField()
  major = CharField()

  #foobar data
  foobar = ChoiceField()

Since some fields (like foobar) are populated from the database i can't use another method other than letting Django render it for me with form.as_ul

Also i wish i don't have to split the form in multiple forms for ease of mantainance

Is there a way to tell Django to display a help text in between these form sections so that i can put in some instructions on how to fill the form?

I'd like the form to render something like this:

<form>

  <p>Here you enter your personal data...</p>
  <input name='firstname'>
  <input name='lastname'>

  <p>Here you enter your education data...</p>
  <input name='university'>
  <input name='major'>

</form>

Would i need to create my own widget to be able to display those <P> tags, or is there an easier way?

Thanks

like image 399
Lorenzo Avatar asked Apr 07 '09 22:04

Lorenzo


1 Answers

There is a help_text field in forms you know.

in forms.py:

  • myField = forms.myFieldType(help_text="Helping friendly text to put in your form", otherStuff=otherStuff)

in forms.html:

  • {{form.myField.help_text}}
like image 126
hendrixski Avatar answered Sep 24 '22 15:09

hendrixski