Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added django.core.validators.isValidHTML

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 17418cd982aa3759ee6fbb0049eec8242faba301 1 parent f5a78ae
@adrianholovaty adrianholovaty authored
Showing with 14 additions and 0 deletions.
  1. +14 −0 django/core/
14 django/core/
@@ -157,6 +157,20 @@ def isValidURL(field_data, all_data):
if not
raise ValidationError, "A valid URL is required."
+def isValidHTML(field_data, all_data):
+ import urllib, urllib2
+ try:
+ u = urllib2.urlopen('', urllib.urlencode({'fragment': field_data, 'output': 'xml'}))
+ except:
+ # Validator or Internet connection is unavailable. Fail silently.
+ return
+ html_is_valid = (u.headers.get('x-w3c-validator-status', 'Invalid') == 'Valid')
+ if html_is_valid:
+ return
+ from xml.dom.minidom import parseString
+ error_messages = [e.firstChild.wholeText for e in parseString('messages')[0].getElementsByTagName('msg')]
+ raise ValidationError, "Valid HTML is required. Specific errors are:\n%s" % "\n".join(error_messages)
def isWellFormedXml(field_data, all_data):
from xml.dom.minidom import parseString
Please sign in to comment.
Something went wrong with that request. Please try again.