﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20703	Why django form.as_p call form.clean method when template renders?	max.kharandziuk@…	nobody	"I have this sample of django code:

    
{{{
# views.py
    def test_view(request):
        form = TestForm(
            request.POST or { 'text': 'some text'},
        )
        data = {
            'form': form,
        }
        print 'before rendering'
        return render(request, 'test.html', data)
    
    # forms.py
    class TestForm(forms.Form):
        text = forms.CharField()
    
        def __init__(self, *args, **kwargs):
            print 'init'
            super(TestForm, self).__init__(*args, **kwargs)
    
        def clean(self):
            print 'in clean'

}}}

and this template:


{{{
    #test.html
    <form id='test-form' method=""post"" action=""some url"" enctype=""multipart/form-data"">
        {{ form.as_p }}
        <input type=""submit"" value=""Save""/>
    </form>
}}}


when i send get request to this file i have this output in console:

> before rendering
> init
> in clean

when I write {{ form.text }} instead of  {{ form.as_p }} I have only:

> before rendering
> init

It seams to me that as_p method calls clean() internally in process of rendering template.
Is it a bug or some undocumented feature?
Should this side effect avoided?

Version of Django==1.5.1"	Uncategorized	closed	Template system	1.5	Normal	invalid	as_p clean templates		Unreviewed	0	0	0	0	0	0
