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.
In this article, we show how to create a URLField in Django. A URLField is a field (of a database table or a form) that stores only URLs. This could be useful for all types of reasons. One glaring example is to let a user enter his or her website.
In Django, views are Python functions which take a URL request as parameter and return an HTTP response or throw an exception like 404. Each view needs to be mapped to a corresponding URL pattern. This is done via a Python module called URLConf(URL configuration) Let the project name be myProject.
Use handy request. build_absolute_uri() method on request, pass it the relative url and it'll give you full one. By default, the absolute URL for request. get_full_path() is returned, but you can pass it a relative URL as the first argument to convert it to an absolute URL.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With