def check_url_or_none(self, url):
if url == '':
url = None
if url is not None:
from urllib.parse import urlparse
parsed_url = urlparse(url)
from pyramid.httpexceptions import HTTPBadRequest
if not parsed_url.scheme:
raise HTTPBadRequest(
"The homepage url does not have a scheme. Must be either http or https"
)
if parsed_url.scheme not in (u'http', u'https'):
raise HTTPBadRequest(
"The url has an incorrect scheme. Only http and https are accepted for homepage url"
)
return url
评论列表
文章目录