MultiValueDictKeyError at / login /" u' username'"

时间:2017-05-25 01:54:32

标签: python django

我正在尝试为登录页面构建一个web api。我一直收到这个错误。虽然我在网上看到过类似的相关问题,但这些解决方案对我有所帮助。我做得不对吗?

错误

Exception in thread "main" java.lang.IllegalArgumentException: The kieBase with kiePackages([]) has no global field called scoreHolder. 
Check if the rule files are found and if the global field is spelled correctly.

登录

MultiValueDictKeyError at /login/
"u'username'"

更新登录

@csrf_exempt
    def my_view(request):
         user = request.POST['username']
         passcode = request.POST['password']
         user = authenticate(request, username=user, password = passcode)
         if user is not None:
             login(request, user)
             return HttpResponse("User logged in")

         else:
             return HttpResponse("User not found")

2 个答案:

答案 0 :(得分:0)

从验证功能

中删除请求参数
user = authenticate (username=username, password=passcode)

修改您的观点,

@csrf_exempt
def my_view(request):
     user = request.POST.get('username')
     password = request.POST.get('password')
     user = authenticate(username=username, password=password)
     if user is not None:
         login(request, user)
         return HttpResponse("User logged in")
     else:
         return HttpResponse("User not found")

答案 1 :(得分:0)

我只使用 request.POST.get('your field_name here')

例如使用 username = request.POST.get('username') 选择您的用户名