views:

34

answers:

1

I have two views

def view1(request):
    do something
    return HttpResponseRedirect(reverse(view2), args1)

Now I need view2 to only work if it's referred by view1. How do I do that? I did read it somewhere, not able to recollect

@somefilter
def view2(request):
    do something
    #view2 will only be referred from view1, else Http404
A: 

I think you should check for the HTTP_REFERER HTTP header. See the documentation. Here is a Django snippet that gives you a decorator to check for referrers.

Manoj Govindan
I would rather return the second view from the first one and not do redirect, then check for HTTP_REFERER since it's not very reliable value specially if you want security implemented this way.
rebus
@rebus: you are right. What you suggested would be a better approach.
Manoj Govindan