summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
Diffstat (limited to 'django')
-rw-r--r--django/forms/fields.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py
index 0143296533..d759da71ab 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -10,6 +10,7 @@ import operator
import os
import re
import uuid
+import warnings
from decimal import Decimal, DecimalException
from io import BytesIO
from urllib.parse import urlsplit, urlunsplit
@@ -42,6 +43,7 @@ from django.forms.widgets import (
)
from django.utils import formats
from django.utils.dateparse import parse_datetime, parse_duration
+from django.utils.deprecation import RemovedInDjango60Warning
from django.utils.duration import duration_string
from django.utils.ipv6 import clean_ipv6_address
from django.utils.regex_helper import _lazy_re_compile
@@ -753,7 +755,19 @@ class URLField(CharField):
}
default_validators = [validators.URLValidator()]
- def __init__(self, **kwargs):
+ def __init__(self, *, assume_scheme=None, **kwargs):
+ if assume_scheme is None:
+ warnings.warn(
+ "The default scheme will be changed from 'http' to 'https' in Django "
+ "6.0. Pass the forms.URLField.assume_scheme argument to silence this "
+ "warning.",
+ RemovedInDjango60Warning,
+ stacklevel=2,
+ )
+ assume_scheme = "http"
+ # RemovedInDjango60Warning: When the deprecation ends, replace with:
+ # self.assume_scheme = assume_scheme or "https"
+ self.assume_scheme = assume_scheme
super().__init__(strip=True, **kwargs)
def to_python(self, value):
@@ -773,8 +787,8 @@ class URLField(CharField):
if value:
url_fields = split_url(value)
if not url_fields[0]:
- # If no URL scheme given, assume http://
- url_fields[0] = "http"
+ # If no URL scheme given, add a scheme.
+ url_fields[0] = self.assume_scheme
if not url_fields[1]:
# Assume that if no domain is provided, that the path segment
# contains the domain.