Ticket #10194: redirect.diff
File redirect.diff, 1.8 KB (added by , 16 years ago) |
---|
-
django/shortcuts/__init__.py
5 5 """ 6 6 7 7 from django.template import loader 8 from django.http import HttpResponse, Http 4048 from django.http import HttpResponse, HttpResponseRedirect, Http404 9 9 from django.db.models.manager import Manager 10 10 from django.db.models.query import QuerySet 11 11 … … 60 60 if not obj_list: 61 61 raise Http404('No %s matches the given query.' % queryset.model._meta.object_name) 62 62 return obj_list 63 64 def redirect( obj ): 65 """ 66 Returns a HttpResponseRedirect, calling get_absolute_url() on the passed 67 argument if it exists. 68 """ 69 redirect_to = hasattr(obj, 'get_absolute_url') and obj.get_absolute_url() or obj 70 return HttpResponseRedirect( redirect_to ) -
docs/topics/http/shortcuts.txt
151 151 my_objects = list(MyModel.objects.filter(published=True)) 152 152 if not my_objects: 153 153 raise Http404 154 155 ``redirect`` 156 ============ 157 158 ``django.shortcuts.redirect`` returns an ``HttpResponseRedirect`` object with 159 the given string or model instance. 160 161 Required arguments 162 ------------------ 163 164 ``redirect_to`` 165 Either a string, or any object with a ``get_absolute_url()`` method defined 166 for it. 167 168 Example 169 ------- 170 171 The following example redirects to a newly-created model instance:: 172 173 from django.shortcuts import redirect 174 175 def my_view(request): 176 if request.method == 'POST': 177 # Create a model instance here... 178 return redirect(model_inst)