How to redirect to previous page in Django after POST request

前端 未结 4 1841
自闭症患者
自闭症患者 2020-12-07 19:03

I face a problem which I can\'t find a solution for. I have a button in navbar which is available on all pages and it is a button responsible for creating some content.

4条回答
  •  青春惊慌失措
    2020-12-07 19:17

    You can use the HTTP_REFERER value:

    return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
    

    Note that this will not work if the client disabled sending referrer information (for example, using a private/incognito browser Window). In such a case it will redirect to /.

提交回复
热议问题