python - Django RegexValidator Not working as expected -
i'm stuck regexvalidator class.
i'm trying allow input of defined html(p, ul, li) tags in character field. next regex need i'm having difficulty implementing it.
<\/?(?!p|ul|li)[^/>]*> i'm trying implment django model in next way:
description = models.charfield(max_length = 255, validators=[ regexvalidator( regex = r'<\/?(?!p|ul|li)[^/>]*>', message = 'disallowed tags', code = 'disallowed_tags', ), ], ) i'm using django 1.6. when implement above code, seems form submissions (using admin interface) fail validation.
any ideas?
thanks
do won validator , if rexep match throw error since shouldn't allowed. here more info validator.
import re django.core.exceptions import validationerror def test(val): if re.match('<\/?(?!p|ul|li)[^/>]*>', val): raise validationerror('disallowed tags') class foo(models.model): name = models.charfield(max_length = 150, validators=[test]) python regex django django-models django-admin
No comments:
Post a Comment