diff --git a/django/contrib/redirects/middleware.py b/django/contrib/redirects/middleware.py
index f5d3594..1aaef17 100644
|
a
|
b
|
|
| 1 | 1 | from __future__ import unicode_literals |
| 2 | 2 | |
| | 3 | from django.conf import settings |
| 3 | 4 | from django.contrib.redirects.models import Redirect |
| 4 | 5 | from django.contrib.sites.models import get_current_site |
| | 6 | from django.core.exceptions import ImproperlyConfigured |
| 5 | 7 | from django import http |
| 6 | | from django.conf import settings |
| 7 | 8 | |
| 8 | 9 | class RedirectFallbackMiddleware(object): |
| | 10 | def __init__(self): |
| | 11 | if 'django.contrib.sites' not in settings.INSTALLED_APPS: |
| | 12 | raise ImproperlyConfigured( |
| | 13 | "You cannot use RedirectFallbackMiddleware when " |
| | 14 | "django.contrib.sites is not installed." |
| | 15 | ) |
| | 16 | |
| 9 | 17 | def process_response(self, request, response): |
| 10 | 18 | if response.status_code != 404: |
| 11 | 19 | return response # No need to check for a redirect for non-404 responses. |
diff --git a/django/contrib/redirects/tests.py b/django/contrib/redirects/tests.py
index 4ea8523..7170520 100644
|
a
|
b
|
|
| 1 | 1 | from django.conf import settings |
| 2 | 2 | from django.contrib.sites.models import Site |
| | 3 | from django.core.exceptions import ImproperlyConfigured |
| 3 | 4 | from django.test import TestCase |
| 4 | 5 | from django.test.utils import override_settings |
| 5 | 6 | from django.utils import six |
| 6 | 7 | |
| | 8 | from .middleware import RedirectFallbackMiddleware |
| 7 | 9 | from .models import Redirect |
| 8 | 10 | |
| 9 | 11 | |
| … |
… |
class RedirectTests(TestCase):
|
| 52 | 54 | site=self.site, old_path='/initial', new_path='') |
| 53 | 55 | response = self.client.get('/initial') |
| 54 | 56 | self.assertEqual(response.status_code, 410) |
| | 57 | |
| | 58 | @override_settings( |
| | 59 | INSTALLED_APPS=[app for app in settings.INSTALLED_APPS |
| | 60 | if app != 'django.contrib.sites']) |
| | 61 | def test_sites_not_installed(self): |
| | 62 | with self.assertRaises(ImproperlyConfigured): |
| | 63 | _ = RedirectFallbackMiddleware() |
diff --git a/docs/ref/contrib/redirects.txt b/docs/ref/contrib/redirects.txt
index e34ba40..0c0cb2a 100644
|
a
|
b
|
Installation
|
| 13 | 13 | |
| 14 | 14 | To install the redirects app, follow these steps: |
| 15 | 15 | |
| 16 | | 1. Add ``'django.contrib.redirects'`` to your :setting:`INSTALLED_APPS` |
| 17 | | setting. |
| 18 | | 2. Add ``'django.contrib.redirects.middleware.RedirectFallbackMiddleware'`` |
| | 16 | 1. Ensure that the ``django.contrib.sites`` framework |
| | 17 | :ref:`is installed <enabling-the-sites-framework>`. |
| | 18 | 2. Add ``'django.contrib.redirects'`` to your :setting:`INSTALLED_APPS` setting. |
| | 19 | 3. Add ``'django.contrib.redirects.middleware.RedirectFallbackMiddleware'`` |
| 19 | 20 | to your :setting:`MIDDLEWARE_CLASSES` setting. |
| 20 | | 3. Run the command :djadmin:`manage.py syncdb <syncdb>`. |
| | 21 | 4. Run the command :djadmin:`manage.py syncdb <syncdb>`. |
| 21 | 22 | |
| 22 | 23 | How it works |
| 23 | 24 | ============ |
diff --git a/docs/ref/contrib/sites.txt b/docs/ref/contrib/sites.txt
index 7eaab5d..139a9b3 100644
|
a
|
b
|
To do this, you can use the sites framework. A simple example::
|
| 246 | 246 | >>> 'http://%s%s' % (Site.objects.get_current().domain, obj.get_absolute_url()) |
| 247 | 247 | 'http://example.com/mymodel/objects/3/' |
| 248 | 248 | |
| | 249 | .. _enabling-the-sites-framework: |
| 249 | 250 | |
| 250 | 251 | Enabling the sites framework |
| 251 | 252 | ============================ |
diff --git a/docs/releases/1.5.txt b/docs/releases/1.5.txt
index a5ce08a..33dcb0e 100644
|
a
|
b
|
Miscellaneous
|
| 653 | 653 | Attempting to load it with ``{% load adminmedia %}`` will fail. If your |
| 654 | 654 | templates still contain that line you must remove it. |
| 655 | 655 | |
| | 656 | * Because of an implementation oversight, it was possible to use |
| | 657 | :doc:`django.contrib.redirects </ref/contrib/redirects>` without enabling |
| | 658 | :doc:`django.contrib.sites </ref/contrib/sites>`. This isn't allowed any |
| | 659 | longer. If you're using ``django.contrib.redirects``, make sure |
| | 660 | :setting:``INSTALLED_APPS`` contains ``django.contrib.sites``. |
| | 661 | |
| 656 | 662 | Features deprecated in 1.5 |
| 657 | 663 | ========================== |
| 658 | 664 | |