python - Django View 可以委托(delegate)给返回响应对象的函数吗?

标签 python django

def process_event(request, eventID, eventData):
    return HttpResponse("process event!")

@csrf_exempt 
@slip_protect
def catch_event(request,eventID):       
    if request.POST:               
        process_event(request,eventID, request.POST['eventData'])
        return HttpResponse("safe return!")

该代码返回“安全返回!”在客户端,而不是“处理事件!”。这是设计和预期的行为吗?我想从一个 View 委托(delegate)给一个函数,函数应该返回一个响应对象。 谢谢。

最佳答案

我猜你想要return process_event(),这样你的 View 就会返回它返回的任何内容

正如目前所读,您的 View 执行 process_event 但丢弃返回的 HttpResponse

关于python - Django View 可以委托(delegate)给返回响应对象的函数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8212307/

相关文章:

python - 在 zappa 中调度 lambda 函数来停止实例

python - 在 OpenCV 中,有些方法只存在于 c++ 中,如何在 python 中做同样的事情?

python - gunicorn - 如果从 shell 脚本执行则不获取配置文件

django模板ModelChoiceField长度

Python: mysqldb 安装错误

python - 如何加快 SQLAlchemy 中的混合属性查询速度?

python - 如何打乱列表的内容并将第一项保持在同一位置?

Django - 自定义身份验证后端中的错误消息

django - 如何使用南将数据从一个字段迁移到另一个表中的字段

Django在 View 中将表单添加到表单集