Django: “Too many values to unpack” when calling user.objects.get()

前端 未结 2 1971
孤独总比滥情好
孤独总比滥情好 2021-02-13 11:16

In Django 1.6, I\'ve defined a custom user model, but for some reason now when I create a superuser and try to get it or access the Django admin as that superuser, I get this

2条回答
  •  野的像风
    2021-02-13 11:27

    Turns out that the problem here was actually very unrelated to the errors thrown.

    I realized I was actually calling

    UserObject.objects.get('user@email.com')
    

    instead of

    UserObject.objects.get(email='user@email.com')
    

    which is why the errors were being thrown. If you look into the Django source code, you'll find that when building a filter for a QuerySet, Django unpacks the field name and data for use in the filter, but since I had provided no field name to objects.get(...), there was an error thrown when unpacking.

    Used the Werkzeug live browser debugger for this; I highly recommend it.

提交回复
热议问题