django URL字段的有效值是多少?

vfc*_*sts 16 django

django URL字段的有效值是多少?

它仅适用于http URL资源还是支持更广泛的范围.例如ssh,rsync,git等

我尝试将我认为有效的Git URL放入其中并且失败了.

因为我没有使用被弃用的verify_exists,所以资源是否存在并不重要.

tba*_*ack 15

它只允许http(s)和ftp(s).这是用于验证URL django.core.validators.URLValidator的正则表达式:

regex = re.compile(
    r'^(?:http|ftp)s?://' # http:// or https://
    r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # domain...
    r'localhost|' # localhost...
    r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|' # ...or ipv4
    r'\[?[A-F0-9]*:[A-F0-9:]+\]?)' # ...or ipv6
    r'(?::\d+)?' # optional port
    r'(?:/?|[/?]\S+)$', re.IGNORECASE)
Run Code Online (Sandbox Code Playgroud)