Skip to content

Instantly share code, notes, and snippets.

@rctay
Created July 4, 2010 04:43
Show Gist options
  • Save rctay/463135 to your computer and use it in GitHub Desktop.
Save rctay/463135 to your computer and use it in GitHub Desktop.
[django] clean field
from clean_field import *
from django.forms.util import ValidationError
def clean_field(form, field_name):
"""
Get the cleaned value of a field, without requiring the entire form to be
valid.
"""
try:
return form.fields[field_name].clean(form.data.get(field_name, None))
except ValidationError:
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment