如何在Django中生成303 Http响应? [英] How to produce a 303 Http Response in Django?

查看:155
本文介绍了如何在Django中生成303 Http响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近几天我们正在另一个问题讨论最好的以RESTful方式管理随机性;今天我在Django里玩了一些想法,只发现有一个简单的标准方法返回一个303响应(也不是一个300的一个btw),也就是说似乎没有一个HttpResponseSeeOther里面django.HTTP或在另一个地方。



你知道有什么办法实现吗?

解决方案

你可能只是覆盖HttpResponse,就像其他响应一样:

  class HttpResponseSeeOther(HttpResponseRedirect):
status_code = 303

return HttpResponseSeeOther('/ other-url /')


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 find that there is no easy standard way of returning a 303 response (nor a 300 one, btw), that is, there doesn't seem to exist an HttpResponseSeeOther inside django.HTTP or in another place.

Do you know any means for achieving this?

解决方案

You could just override HttpResponse, like the other Responses do:

class HttpResponseSeeOther(HttpResponseRedirect):
    status_code = 303

return HttpResponseSeeOther('/other-url/')

这篇关于如何在Django中生成303 Http响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆