def new_topic(request):
"""add new topic"""
if request.method != 'POST':
form = TopicForm()
else:
form = TopicForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('learning_logs:topics'))
context = {'form': form}
return render(request, 'learning_logs/new_topic.html', context)
我得到的错误:
视图learning_logs.views.new_topic未返回HttpResponse对象。它返回了None。
我已经搜索了很多相关的问题并对它们进行了测试,但它们没有用。请你帮我一下,谢谢。
答案 0 :(得分:0)
def new_topic(request):
"""add new topic"""
if request.method == 'POST':
form = TopicForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('learning_logs:topics'))
else:
form = TopicForm()
return render(request, 'learning_logs/new_topic.html', {'form': form})