Changeset 1816
- Timestamp:
- 01/03/06 17:57:14 (3 years ago)
- Files:
-
- django/trunk/django/contrib/redirects/middleware.py (modified) (1 diff)
- django/trunk/django/middleware/common.py (modified) (1 diff)
- django/trunk/django/utils/httpwrappers.py (modified) (1 diff)
- django/trunk/django/views/generic/simple.py (modified) (1 diff)
- django/trunk/docs/request_response.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/contrib/redirects/middleware.py
r1166 r1816 22 22 if r == '': 23 23 return httpwrappers.HttpResponseGone() 24 return httpwrappers.HttpResponse Redirect(r.new_path)24 return httpwrappers.HttpResponsePermanentRedirect(r.new_path) 25 25 26 26 # No redirect was found. Return the response. django/trunk/django/middleware/common.py
r1548 r1816 47 47 if request.GET: 48 48 newurl += '?' + request.GET.urlencode() 49 return httpwrappers.HttpResponse Redirect(newurl)49 return httpwrappers.HttpResponsePermanentRedirect(newurl) 50 50 51 51 return None django/trunk/django/utils/httpwrappers.py
r1505 r1816 213 213 self.status_code = 302 214 214 215 class HttpResponsePermanentRedirect(HttpResponse): 216 def __init__(self, redirect_to): 217 HttpResponse.__init__(self) 218 self['Location'] = redirect_to 219 self.status_code = 301 220 215 221 class HttpResponseNotModified(HttpResponse): 216 222 def __init__(self): django/trunk/django/views/generic/simple.py
r1249 r1816 1 1 from django.core.extensions import DjangoContext, render_to_response 2 from django.utils.httpwrappers import HttpResponse, HttpResponse Redirect, HttpResponseGone2 from django.utils.httpwrappers import HttpResponse, HttpResponsePermanentRedirect, HttpResponseGone 3 3 4 4 def direct_to_template(request, template, **kwargs): 5 5 """ 6 Render a given template with any extra URL parameters in the context as 6 Render a given template with any extra URL parameters in the context as 7 7 ``{{ params }}``. 8 8 """ 9 9 return render_to_response(template, {'params' : kwargs}, context_instance=DjangoContext(request)) 10 10 11 11 def redirect_to(request, url, **kwargs): 12 12 """ 13 Redirect to a given URL. 14 15 The given url may contain dict-style string formatting which will be13 Redirect to a given URL. 14 15 The given url may contain dict-style string formatting, which will be 16 16 interpolated against the params in the URL. For example, to redirect from 17 ``/foo/<id>/`` to ``/bar/<id>/``, you could use the following urlpattern::17 ``/foo/<id>/`` to ``/bar/<id>/``, you could use the following URLconf:: 18 18 19 19 urlpatterns = patterns('', 20 20 ('^foo/(?p<id>\d+)/$', 'django.views.generic.simple.redirect_to', {'url' : '/bar/%(id)s/'}), 21 21 ) 22 22 23 23 If the given url is ``None``, a HttpResponseGone (410) will be issued. 24 24 """ 25 25 if url is not None: 26 return HttpResponse Redirect(url % kwargs)26 return HttpResponsePermanentRedirect(url % kwargs) 27 27 else: 28 28 return HttpResponseGone() django/trunk/docs/request_response.txt
r1504 r1816 358 358 The constructor takes a single argument -- the path to redirect to. This 359 359 can be a fully qualified URL (e.g. ``"http://www.yahoo.com/search/"``) or an 360 absolute URL with no domain (e.g. ``"/search/"``). 360 absolute URL with no domain (e.g. ``"/search/"``). Note that this returns 361 an HTTP status code 302. 362 363 ``HttpResponsePermanentRedirect`` 364 **New in Django development version.*** 365 366 Like ``HttpResponseRedirect``, but it returns a permanent redirect (HTTP 367 status code 301) instead of a "found" redirect (status code 302). 361 368 362 369 ``HttpResponseNotModified``
