Should I use HTTP 4xx to indicate HTML form errors?

前端 未结 4 1094
滥情空心
滥情空心 2020-12-19 04:33

I just spent 20 minutes debugging some (django) unit tests. I was testing a view POST, and I was expecting a 302 return code, after which I asserted a bunch database entitie

4条回答
  •  春和景丽
    2020-12-19 04:41

    The POST returns 200 if you do not redirect. The 302 is not sent automatically in headers after POST request, so you have to send the header (https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponse) manually and the code does not relay on data of the form.

    The reason of the redirection back to the form (or whatever) with code 302 is to disallow browser to send the data repeatedly on refresh or history browsing.

提交回复
热议问题