"UserFav.user" must be a "UserProfile" instance.
来源:8-3 用户收藏接口实现
慕妹4270370
2019-05-05
我检查了代码 跟下载的一样,怎么解决呢?
ValueError at /userfavs/
Cannot assign "<django.contrib.auth.models.AnonymousUser object at 0x0000027597551EF0>": "UserFav.user" must be a "UserProfile" instance.
Request Method: POST
Request URL: http://127.0.0.1:8000/userfavs/
Django Version: 1.11
Exception Type: ValueError
Exception Value:
Cannot assign "<django.contrib.auth.models.AnonymousUser object at 0x0000027597551EF0>": "UserFav.user" must be a "UserProfile" instance.
Exception Location: D:\Envs\MxShop\lib\site-packages\django\db\models\fields\related_descriptors.py in __set__, line 216
Python Executable: D:\Envs\MxShop\Scripts\python.exe
Python Version: 3.6.0
Python Path:
['C:\\Users\\huang\\PycharmProjects\\MxShop\\extra_apps',
'C:\\Users\\huang\\PycharmProjects\\MxShop\\apps',
'C:\\Users\\huang\\PycharmProjects\\MxShop',
'C:\\Users\\huang\\PycharmProjects\\MxShop',
'C:\\Program Files\\JetBrains\\PyCharm 2018.2.4\\helpers\\pydev',
'C:\\Users\\huang\\PycharmProjects\\MxShop',
'C:\\Users\\huang\\PycharmProjects\\MxShop\\apps',
'C:\\Users\\huang\\PycharmProjects\\MxShop\\extra_apps',
'C:\\Program Files\\JetBrains\\PyCharm 2018.2.4\\helpers\\pydev',
'C:\\Users\\huang\\.PyCharm2018.2\\system\\cythonExtensions',
'D:\\Envs\\MxShop\\Scripts\\python36.zip',
'C:\\Users\\huang\\AppData\\Local\\Programs\\Python\\Python36\\DLLs',
'C:\\Users\\huang\\AppData\\Local\\Programs\\Python\\Python36\\lib',
'C:\\Users\\huang\\AppData\\Local\\Programs\\Python\\Python36',
'D:\\Envs\\MxShop',
'D:\\Envs\\MxShop\\lib\\site-packages',
'D:\\Envs\\MxShop\\lib\\site-packages\\setuptools-39.1.0-py3.6.egg',
'C:\\Program Files\\JetBrains\\PyCharm '
'2018.2.4\\helpers\\pycharm_matplotlib_backend']
Server time: 星期日, 5 五月 2019 15:09:54 +0800
写回答
1回答
-
Ethreal
2019-05-06
你还是检查下userfav的这个区域把 肯定不是传递的user 实例过去 通过django抛出的异常都会显示在多少行区域 你在仔细对比下
022020-12-26
Python前后端分离开发Vue+Django REST framework实战
Django REST framework课程视频,RESTFul API前后端分离开发
2872 学习 · 2457 问题
相似问题