How to produce a 303 Http Response in Django?

前端 未结 2 1209
轻奢々
轻奢々 2021-02-07 04:24

Last couple of days we were discussing at another question the best to manage randomness in a RESTful way; today I went to play a little bit with some ideas in Django only to fi

2条回答
  •  悲哀的现实
    2021-02-07 05:03

    The generic HttpResponse object lets you specify any status code you want:

    response = HttpResponse(content="", status=303)
    response["Location"] = "http://example.com/redirect/here/"
    

    If you need something re-usable then Gerald's answer is definitely valid; simply create your own HttpResponseSeeOther class. Django only provides these specific classes for a few of the most common status codes.

提交回复
热议问题