Python wtforms.validators.URL Examples
The following are 4
code examples of wtforms.validators.URL().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
wtforms.validators
, or try the search function
.
Example #1
Source File: validators.py From arch-security-tracker with MIT License | 6 votes |
def __init__(self): self.message = ERROR_INVALID_URL self.regex = URLValidator().regex
Example #2
Source File: forms.py From notifications-admin with MIT License | 6 votes |
def validate(self): if self.contact_details_type.data == 'url': self.url.validators = [DataRequired(), URL(message='Must be a valid URL')] elif self.contact_details_type.data == 'email_address': self.email_address.validators = [DataRequired(), Length(min=5, max=255), ValidEmail()] elif self.contact_details_type.data == 'phone_number': # we can't use the existing phone number validation functions here since we want to allow landlines def valid_phone_number(self, num): try: normalise_phone_number(num.data) return True except InvalidPhoneError: raise ValidationError('Must be a valid phone number') self.phone_number.validators = [DataRequired(), Length(min=5, max=20), valid_phone_number] return super().validate()
Example #3
Source File: inventory_update_form.py From cog with GNU Affero General Public License v3.0 | 4 votes |
def validate_image(form, field): if field.data == field.default: return True url_validator = validators.URL() return url_validator(form, field)
Example #4
Source File: remedy_utils.py From radremedy with Mozilla Public License 2.0 | 4 votes |
def get_field_args(field, **kwargs): """ Generates a dictionary of arguments to be used when rendering out a form field. Args: field: The form field to render. **kwargs: Any additional arguments to include for the form field. Returns: A dictionary of arguments to use to render out a form field. """ # Set up our default args field_args = { "class_": "form-control" } # Handle required fields if field.flags.required: field_args['required'] = 'required' # Look at field validators for val in field.validators: # Handle minlength/maxlength attributes if specified on # string fields through a Length validator if isinstance(val, Length): if val.min > 0: field_args['minlength'] = val.min if val.max > 0: field_args['maxlength'] = val.max elif isinstance(val, Email): field_args['type'] = 'email' elif isinstance(val, URL): field_args['type'] = 'url' elif isinstance(val, NumberRange): if val.min is not None: field_args['min'] = val.min if val.max is not None: field_args['max'] = val.max # If we have a description, create an aria-described by attribute if field.description and len(field.description) > 0: field_args['aria-describedby'] = field.id + '_help' # Merge in extra arguments field_args.update(kwargs) # Default rows for textareas if not specified if 'rows' not in field_args and field.type == 'TextAreaField': field_args['rows'] = '3' return field_args