You could create a custom validator to strip the http/https before further processing:
import re
db.url.URL.requires = [lambda url: (re.sub(r'http[s]?://', '', url), None),
IS_URL(error_message='URL Error'),
IS_NOT_IN_DB(db, 'url.URL',error_message='Dupilcated URL')]
Note, the custom validator returns a tuple including the altered URL and None
(the None
indicates that there is no error). That altered URL is then passed to the remaining two validators.
Note, by default, IS_URL
will prepend "http://" to any URL that lacks a scheme (which will be all URLs in this case, since the first validator strips the scheme). To suppress that behavior, you can do IS_URL(prepend_scheme=None)
.