What the difference between using Django redirect and HttpResponseRedirect?

前端 未结 2 599
萌比男神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条回答
  •  野性不改
    2021-01-30 01:22

    There is a difference between the two:

    In the case of HttpResponseRedirect the first argument can only be a url.

    redirect which will ultimately return a HttpResponseRedirect can accept a model, view, or url as it's "to" argument. So it is a little more flexible in what it can "redirect" to.

    I also like how redirect is shorter. So I'd use redirect over HttpResponseRedirect.

    Both are fine to use though.

提交回复
热议问题