0

I'm trying to implement a generic view that performs some pre-processing and redirects to an external website. Essentially I want to query and update the database before performing the redirect each time the view is accessed.

I spotted Python + Django page redirect but this only deals with simple redirects and not with generic views.

Can anyone provide an example on how this should be implemented?

Any help you can give would be greatly appreciated,

Niall

Community
  • 1
  • 1
eageranalyst
  • 1,016
  • 9
  • 15

1 Answers1

3

If you just want to do some processing before performing a redirect, I'm not seeing how generic views come into play for you. You can customize generic views by wrapping them in another function, or in the case of class-based generic views, subclassing them. In your situation, I fail to see how they'd benefit you much, just write a normal view, and use redirect:

from django.shortcuts import redirect

def my_view(request):
    ...do some processing
    return redirect('/some/url/')

Not going to get easier than that.

Zach Kelling
  • 52,505
  • 13
  • 109
  • 108
  • OK, thanks. I thought that as Generic Views were the new preferred way of doing things that there might be a way to do this using them. Using your method and it's working great. – eageranalyst Jun 15 '11 at 19:57