gak*_*gak 26
您可以像其他响应一样覆盖HttpResponse:
class HttpResponseSeeOther(HttpResponseRedirect):
status_code = 303
return HttpResponseSeeOther('/other-url/')
Run Code Online (Sandbox Code Playgroud)
nez*_*roy 20
通用的HttpResponse对象允许您指定所需的任何状态代码:
response = HttpResponse(content="", status=303)
response["Location"] = "http://example.com/redirect/here/"
Run Code Online (Sandbox Code Playgroud)
如果您需要可重复使用的东西,那么Gerald的答案肯定是有效的; 只需创建自己的HttpResponseSeeOther类.Django仅为一些最常见的状态代码提供这些特定类.
归档时间: |
|
查看次数: |
5714 次 |
最近记录: |