Additional information with widgets in django
I am displaying a django widget, with which I need to display additional information (something like a tool tip) that is attendant to the widget. I essentially have a widget that asks a random question, which is self contained.
{{ form.fieldname }}
displays the full widget which looks something like (à la the widget's render method):
<label for="id_answer">Question:</label>
<input type="hidden" name="question开发者_StackOverflow_id" value="n" />
<span class="prompt">What is the air-speed velocity of an unladen swallow?</span>
<input type="text" name="answer" />
What I'm essentially asking is, is there a way to break out the prompt, so that I can lay the widget out piecemeal? I would like to lay it out not with a call to {{ form.fieldname }} as above, but like:
{{ form.fieldname.label }}
{{ form.fieldname.prompt }}
{{ form.fieldname }}
Does anyone know how to do this?
Something like this?
<form action="/contact/" method="post">
{% for field in form %}
<div class="fieldWrapper">
{{ field.errors }}
{{ field.label_tag }}: {{ field }}
</div>
{% endfor %}
<p><input type="submit" value="Send message" /></p>
</form>
The goal is to do as rebus suggests, except with the caveat of an additional attribute of field which would be field.prompt (or arbitrarily named).
Something like this:
<form action="/contact/" method="post">
{% for field in form %}
<div class="fieldWrapper">
{{ field.errors }}
{{ field.a_custom_method }} // called "prompt" in the op
{{ field.label_tag }}: {{ field }}
</div>
{% endfor %}
<p><input type="submit" value="Send message" /></p>
精彩评论