开发者

Writing a django view that does not return an object

开发者 https://www.devze.com 2023-02-23 22:46 出处:网络
I am writing a django view that just post some data and update a variable in the database. The view will not开发者_运维知识库 return anything as I am submitting the data using jquery-ajax.

I am writing a django view that just post some data and update a variable in the database. The view will not开发者_运维知识库 return anything as I am submitting the data using jquery-ajax.

I am getting the following error:

The view mysite.views.home didn't return an HttpResponse object

Again I do not wish to return an html page or anything of that sort. How can I achieve that?


return HttpResponse("")

I usually do:

return HttpResponse("OK")

just because. In case I want to add error codes in later.


A view in Django must return a HttpResponse, even if it's empty.


You still need to return an HttpResponse, even for an Ajax query. If you're sure it doesn't need any content, you can return an empty one:

return HttpResponse('')

but I would at least put 'ok' to indicate to your Javascript that everything went correctly.

0

精彩评论

暂无评论...
验证码 换一张
取 消