<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Django foo &#187; clean</title>
	<atom:link href="http://www.djangofoo.com/tag/clean/feed" rel="self" type="application/rss+xml" />
	<link>http://www.djangofoo.com</link>
	<description>Django Tips and Tweaks</description>
	<lastBuildDate>Wed, 18 Aug 2010 09:38:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Show form errors (non field errors)</title>
		<link>http://www.djangofoo.com/61/show-form-errors-non-fiel-errors</link>
		<comments>http://www.djangofoo.com/61/show-form-errors-non-fiel-errors#comments</comments>
		<pubDate>Fri, 05 Feb 2010 16:14:32 +0000</pubDate>
		<dc:creator>Davo</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[clean]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[non_field_errors]]></category>
		<category><![CDATA[validate]]></category>

		<guid isPermaLink="false">http://www.djangofoo.com/?p=61</guid>
		<description><![CDATA[In the current Django version it is possible to implement form validation by overriding the clean() function. For instance a ContactForm: class ContactForm(forms.Form): # ... fields... field1 = forms.IntegerField() def clean(self) cleaned_data = self.cleaned_data f = cleaned_data.get('field1') if f > 10: raise forms.ValidationError("Did you just enter more than 10?") return cleaned_data # Never forget this [...]]]></description>
			<content:encoded><![CDATA[<p>In the current Django version it is possible to implement form validation by overriding the <strong>clean()</strong> function.<br />
For instance a ContactForm:</p>
<pre class="brush: python">
class ContactForm(forms.Form):
    # ... fields...
   field1 = forms.IntegerField()

   def clean(self)
       cleaned_data = self.cleaned_data
       f = cleaned_data.get('field1')
       if f > 10:
          raise forms.ValidationError("Did you just enter more than 10?")
       return cleaned_data # Never forget this otherwise you will end up with empty request.POST in the views.py.
</pre>
<p>In order to show that &#8220;Did you just enter more than 10&#8243; error in the template: </p>
<pre class="brush: python">
&lt;!-- assuming that you have form as ContactForm. --&gt;
{{ <strong>form.non_field_errors</strong> }}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.djangofoo.com/61/show-form-errors-non-fiel-errors/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

