vfclists
vfclists

Reputation: 20261

What are the valid values for a django URL field?

What are the valid values for a django URL field?

Is it only for http URL resources or does it support a wider range. eg ssh, rsync, git etc.

I tried putting what I considered to be valid Git URL and it failed.

Because I am not using the verify_exists which is being deprecated it doesn't matter whether the resource exists or not.

Upvotes: 17

Views: 6892

Answers (1)

tback
tback

Reputation: 11571

It allows http(s) and ftp(s) only. This is the regular expression used to validate urls 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)

Upvotes: 16

Related Questions