Django

Code

Changeset 1816

Show
Ignore:
Timestamp:
01/03/06 17:57:14 (3 years ago)
Author:
adrian
Message:

Fixed #1117 -- Added HttpResponsePermanentRedirect?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/contrib/redirects/middleware.py

    r1166 r1816  
    2222            if r == '': 
    2323                return httpwrappers.HttpResponseGone() 
    24             return httpwrappers.HttpResponseRedirect(r.new_path) 
     24            return httpwrappers.HttpResponsePermanentRedirect(r.new_path) 
    2525 
    2626        # No redirect was found. Return the response. 
  • django/trunk/django/middleware/common.py

    r1548 r1816  
    4747            if request.GET: 
    4848                newurl += '?' + request.GET.urlencode() 
    49             return httpwrappers.HttpResponseRedirect(newurl) 
     49            return httpwrappers.HttpResponsePermanentRedirect(newurl) 
    5050 
    5151        return None 
  • django/trunk/django/utils/httpwrappers.py

    r1505 r1816  
    213213        self.status_code = 302 
    214214 
     215class HttpResponsePermanentRedirect(HttpResponse): 
     216    def __init__(self, redirect_to): 
     217        HttpResponse.__init__(self) 
     218        self['Location'] = redirect_to 
     219        self.status_code = 301 
     220 
    215221class HttpResponseNotModified(HttpResponse): 
    216222    def __init__(self): 
  • django/trunk/django/views/generic/simple.py

    r1249 r1816  
    11from django.core.extensions import DjangoContext, render_to_response 
    2 from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect, HttpResponseGone 
     2from django.utils.httpwrappers import HttpResponse, HttpResponsePermanentRedirect, HttpResponseGone 
    33 
    44def direct_to_template(request, template, **kwargs): 
    55    """ 
    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 
    77    ``{{ params }}``. 
    88    """ 
    99    return render_to_response(template, {'params' : kwargs}, context_instance=DjangoContext(request)) 
    10      
     10 
    1111def redirect_to(request, url, **kwargs): 
    1212    """ 
    13     Redirect to a given URL.   
    14      
    15     The given url may contain dict-style string formatting which will be 
     13    Redirect to a given URL. 
     14 
     15    The given url may contain dict-style string formatting, which will be 
    1616    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:: 
    1818 
    1919        urlpatterns = patterns('', 
    2020            ('^foo/(?p<id>\d+)/$', 'django.views.generic.simple.redirect_to', {'url' : '/bar/%(id)s/'}), 
    2121        ) 
    22          
     22 
    2323    If the given url is ``None``, a HttpResponseGone (410) will be issued. 
    2424    """ 
    2525    if url is not None: 
    26         return HttpResponseRedirect(url % kwargs) 
     26        return HttpResponsePermanentRedirect(url % kwargs) 
    2727    else: 
    2828        return HttpResponseGone() 
  • django/trunk/docs/request_response.txt

    r1504 r1816  
    358358    The constructor takes a single argument -- the path to redirect to. This 
    359359    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). 
    361368 
    362369``HttpResponseNotModified``