diff --git a/src/wtforms/validators.py b/src/wtforms/validators.py index 3c0db3b09..730ba17ae 100644 --- a/src/wtforms/validators.py +++ b/src/wtforms/validators.py @@ -511,11 +511,13 @@ class URL(Regexp): If true, then the domain-name portion of the URL must contain a .tld suffix. Set this to false if you want to allow domains like `localhost`. + :param allow_ip: + If false, then give ip as host will fail validation :param message: Error message to raise in case of a validation error. """ - def __init__(self, require_tld=True, message=None): + def __init__(self, require_tld=True, allow_ip=True, message=None): regex = ( r"^[a-z]+://" r"(?P[^\/\?:]+)" @@ -525,7 +527,7 @@ def __init__(self, require_tld=True, message=None): ) super().__init__(regex, re.IGNORECASE, message) self.validate_hostname = HostnameValidation( - require_tld=require_tld, allow_ip=True + require_tld=require_tld, allow_ip=allow_ip ) def __call__(self, form, field):