Redirect / return to same (previous) page in Django?

前端 未结 4 879
滥情空心
滥情空心 2020-12-04 16:36

What are the options when you want to return the user to the same page in Django and what are the pros/cons of each?

Methods I know:

  • HTTP_REFERER
4条回答
  •  误落风尘
    2020-12-04 17:00

    One of the way is using HTTP_REFERER header like as below:

    from django.http import HttpResponseRedirect
    
    def someview(request):
       ...
       return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
    

    Not sure of cons of this!

提交回复
热议问题