视图music.views.favorite没有返回HttpResponse对象。它返回了None

时间:2017-03-11 20:53:46

标签: django http

enter image description here

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\django-1.10.6-py3.4.egg\django\core\handlers\exception.py", line 42, in inner
response = get_response(request)
  File "C:\Python34\lib\site-packages\django-1.10.6-py3.4.egg\django\core\handlers\base.py", line 198, in _get_response
"returned None instead." % (callback.__module__, view_name)
ValueError: The view music.views.favorite didn't return an HttpResponse object. It returned None instead.
[11/Mar/2017 15:34:57] "POST /music/1/favorite/ HTTP/1.1" 500 56886

1 个答案:

答案 0 :(得分:0)

那是因为在你的else条款中,你没有返回任何东西!您只是保存selected_song。您应该返回一个HttpResponse对象(即通常使用renderHttpResponseRedirect