我正在用django为我的大学作业做一个项目。我想用django做一个跟随系统,我写了代码,得到了以下错误
cannot unpack non-iterable Profile object
在模型.py在
class Profile(models.Model):
user=models.OneToOneField(User, on_delete=models.CASCADE)
image=models.ImageField(default='default.jpg',upload_to='profile_pics',blank=True)
description=models.TextField(max_length=200, blank=True)
following = models.ManyToManyField(User, related_name='followed_by', blank=True)
def __str__(self):
return f'{self.user.username} Profile'
def saveimg(self):
super().save()
img=Image.open(self.image.path)
if img.height>300 or img.width>300:
output_size=(300,300)
img.thumbnail(output_size)
img.saveimg(self.image.path)
在视图.py在
^{pr2}$在网址.py在
path('user/<str:username>/follow', views.follow_user,name='follow_user'),
回溯
回溯:
File "C:\Users\Mustafa Lakhani\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\handlers\exception.py" in inner 34. response = get_response(request)
File "C:\Users\Mustafa Lakhani\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\handlers\base.py" in _get_response 126. response = self.process_exception_by_middleware(e, request)
File "C:\Users\Mustafa Lakhani\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\handlers\base.py" in _get_response 124. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "D:\sb\blog\views.py" in follow_user 186. if request.user.profile.following.filter(creator).exists():
File "C:\Users\Mustafa Lakhani\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\manager.py" in manager_method 82. return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\Mustafa Lakhani\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\query.py" in filter 844. return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Users\Mustafa Lakhani\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\query.py" in _filter_or_exclude 862. clone.query.add_q(Q(*args, **kwargs))
File "C:\Users\Mustafa Lakhani\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\sql\query.py" in add_q 1263. clause, _ = self._add_q(q_object, self.used_aliases)
File "C:\Users\Mustafa Lakhani\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\sql\query.py" in _add_q 1287. split_subq=split_subq,
File "C:\Users\Mustafa Lakhani\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\sql\query.py" in build_filter 1161. arg, value = filter_expr
Exception Type: TypeError at /user/mustafalakhani/follow Exception Value: cannot unpack non-iterable Profile object
目前没有回答
相关问题 更多 >
编程相关推荐