MultiValueDictKeyError at /user/ ‘users‘

def addbook(request):
    if request.method == 'POST':
        book_name =request.POST['book_name']
    Book = Book.objects.get()
        Book.save()
        return render_to_response('book_detail.html', {'books': books},context_instance=RequestContext(request))
    else:
        return render_to_response('addbook.html',context_instance=RequestContext(request))

def book_detail(request):
    return render(request, 'book_detail.html')
问题描述
MultiValueDictKeyError at /addbook
# 解决方案
改为 request.Post.get('book_name')
即由POST方法 改为get方法,有效解决问题。
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页