i'm experimenting http error codes in django have question httpresponse(status=<code>). example, want send http error code 405, have following code:
def myview(request): if request.method == 'post': ... else: return httpresponse(status=405) also have template http error code (405.html) , put following code line in urls.py
handler405 = 'handling_error.views.bad_method' and bad_method view following:
def bad_method(request): datos_template = {} return render(request, '405.html', datos_template, status=405) i thought in way django redirect correct template according http error code, doesn't work, then:
have done incorrect something? how httpresponse(status=) work in django? goal of sending http error code through httpresponse(status=)?
sorry, many questions :p
i hope can me.
httpresponse(status=[code]) way of sending actual http status code in header of response. arrives @ client status_code, not changing of data except http header. can pass status code properly-working response, , still show before, if go browser's console see read "405" page.
http headers transferred each request , response web server parsing , providing metadata/info developers. 404 pages have content sent them, tell user there 404; if didn't, user blank page , have no idea went wrong.
if want signify error, can take @ these docs. alternatively, can use httpresponseredirect (see here) option direct error-view serves custom error response.
Comments
Post a Comment