Ticket #4238: redirect_to_absolute_url.py

File redirect_to_absolute_url.py, 469 bytes (added by David Cramer <dcramer@…>, 8 years ago)

untested code

Line 
1from django.http import HttpResponse
2
3def redirect_to_absolute_url(model, **kwargs):
4        """
5        Redirects to the absolute url of a model
6
7        Requires a model class to be passed
8        as well as lookup kwargs
9                from myapp.models import MyModel
10                urlpatterns = patterns('',
11                        ('^foo/(?P<id>\d+)/$', 'django.views.simple.redirect_to_absolute_url', {'model': MyModel: 'pk': '%(id)s'}),
12                        )
13        """
14        obj = model.objects.get(**kwargs)
15        return HttpResponseRedirect(obj.get_absolute_url())
Back to Top