首先,我希望两个视图都使用完全相同的 URL,因为我不想让我的 URLConf 更复杂。我想要 GET 和 POST 的单独视图以使我的代码更清晰。代码是这样的:
def view2 (request):
# handle POST request, possibly a ajax one
return HTTPRESPONSE(json_data, mimetype="Application/JSON")
def view1 (request):
if method == POST:
view2(request)
# What should I return here???
else:
# handle GET
return render(request, template, context)
我的问题是关于这# What should I return here???
条线的。如果我不在那里退货,则会发生错误:
不返回http响应
但是我已经在 view2 中返回了一个 HTTP 响应。我怎样才能使这项工作?