Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the valid values for a django URL field?

Tags:

django

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.

like image 301
vfclists Avatar asked Jan 08 '12 14:01

vfclists


People also ask

What is URL field in Django?

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.

What is URL patterns in Django?

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.

How do I get an absolute URL in Django?

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.


1 Answers

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)
like image 158
tback Avatar answered Oct 19 '22 22:10

tback