What the difference between using Django redirect and HttpResponseRedirect?

前端 未结 2 577
萌比男神i
萌比男神i 2021-01-30 00:51

Which is it better to use generally?

  • https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#redirect

  • https://docs.djangoproject.com/en/dev

2条回答
  •  萌比男神i
    2021-01-30 01:19

    From documentation -

    redirect(to[, permanent=False], *args, **kwargs) Returns an HttpResponseRedirect to the appropriate URL for the arguments passed.

    from the definition its the same. Thats what shortcuts are for. Both are one and the same.

    shortcuts generally are written one level above the actual API's. So redirect encapsulates HttpResponseRedirect and HttpResponsePermanentRedirect with the arg permanent=False.

    There is no major downside to using HttpResponseRedirect over redirect. Hope this clears it.

提交回复
热议问题