Hi all,

How do i get the actual data for a form field in the DJango template?
field.data does not seem to work all the time.

I saw the following:
http://yuji.wordpress.com/2008/06/12/django-how-to-get-only-the-data-from-a-form-field/

which is exactly what i want to do, but field.data seems to return
None for initial data. I.e. on GET request, I query the data for the
form from the database and display it in a form. However the
field.data shows None not the data from the model i queried. Note
however that the initial values in the form elements are correct.

In my view i have:

def developer_view_or_update(request, developer_id):
        d = get_object_or_404(Developer, pk=developer_id)
        if request.method == 'POST':
                form = DeveloperForm(request.POST)
                if form.is_valid():
                        pass # @@@Brendon Later will do stuff
        else:
                form = DeveloperForm(instance=d)

        return render_to_response('DAN/web/detail.html', {'form':
DeveloperForm(instance=d)}, context_instance=RequestContext(request))


My template:
<form method="post" action="" >
{% for field in form %}
        {{ field.name }} :
        {{ field.data }}<br />

        {{ field.label_tag }}: {{ field }}<br />
{% endfor %}

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to