summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorNick Pope <nick@nickpope.me.uk>2015-05-03 23:08:28 +0100
committerTim Graham <timograham@gmail.com>2015-06-18 10:18:12 -0400
commitb3d5dc6932bf896a909e9871d508654494b34563 (patch)
treed995b27a4f985faa8b3edcb98c38ba2cf799f817 /docs
parent7f1168e387dc1db70b6093cfd23a4a6978f48109 (diff)
Fixed #24834 -- Fixed get_current_site() when Host header contains port.
When the Host header contains a port, looking up the Site record fails as the host will never match the domain.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/contrib/sites.txt21
-rw-r--r--docs/releases/1.9.txt6
2 files changed, 22 insertions, 5 deletions
diff --git a/docs/ref/contrib/sites.txt b/docs/ref/contrib/sites.txt
index 4928c92119..da2bd879db 100644
--- a/docs/ref/contrib/sites.txt
+++ b/docs/ref/contrib/sites.txt
@@ -495,10 +495,23 @@ Finally, to avoid repetitive fallback code, the framework provides a
A function that checks if ``django.contrib.sites`` is installed and
returns either the current :class:`~django.contrib.sites.models.Site`
object or a :class:`~django.contrib.sites.requests.RequestSite` object
- based on the request.
+ based on the request. It looks up the current site based on
+ :meth:`request.get_host() <django.http.HttpRequest.get_host>` if the
+ :setting:`SITE_ID` setting is not defined.
+
+ Both a domain and a port may be returned by :meth:`request.get_host()
+ <django.http.HttpRequest.get_host>` when the Host header has a port
+ explicitly specified, e.g. ``example.com:80``. In such cases, if the
+ lookup fails because the host does not match a record in the database,
+ the port is stripped and the lookup is retried with the domain part
+ only. This does not apply to
+ :class:`~django.contrib.sites.requests.RequestSite` which will always
+ use the unmodified host.
.. versionchanged:: 1.8
- This function will now lookup the current site based on
- :meth:`request.get_host() <django.http.HttpRequest.get_host>` if the
- :setting:`SITE_ID` setting is not defined.
+ Looking up the current site based on ``request.get_host()`` was added.
+
+ .. versionchanged:: 1.9
+
+ Retrying the lookup with the port stripped was added.
diff --git a/docs/releases/1.9.txt b/docs/releases/1.9.txt
index 4b7ef5184a..73ed556d31 100644
--- a/docs/releases/1.9.txt
+++ b/docs/releases/1.9.txt
@@ -208,7 +208,11 @@ Minor features
:mod:`django.contrib.sites`
^^^^^^^^^^^^^^^^^^^^^^^^^^^
-* ...
+* :func:`~django.contrib.sites.shortcuts.get_current_site` now handles the case
+ where ``request.get_host()`` returns ``domain:port``, e.g.
+ ``example.com:80``. If the lookup fails because the host does not match a
+ record in the database and the host has a port, the port is stripped and the
+ lookup is retried with the domain part only.
:mod:`django.contrib.staticfiles`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^