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

前端 未结 4 878
滥情空心
滥情空心 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

    While the question and answer is old, I think it's lacking a few options. I have not find any cons with the methods, I would be happy to know if there are any?

    • request.path_info
    • request.get_full_path()
    • request.build_absolute_uri()

      from django.shortcuts import redirect
      
      redirect(request.path_info) # No query parameters
      
      redirect(request.build_absolute_uri()) # Keeps query parameters
      
      redirect(request.get_full_path()) # Keeps query parameters
      

提交回复
热议问题