开发者

Django:How can I ensure that a view can only be directed from another view

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 vie开发者_C百科w1, else Http404


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜