django 做的网站出现如下错误:
Exception Type:
TypeError Exception Value:'AnonymousUser' object is not iterable
错误代码最终定位在view视图:
if UserFavorite.objects.filter(user=request.user, fav_type=2,av_id=teacher.org.id):
错误分析,此功能必须经过验证登录的用户才能使用,没登录的用户使用了此功能导致报错,解决办法,在报错的代码前面加上如下代码:
if request.user.is_authenticated():
if UserFavorite.objects.filter(user=request.user, fav_type=3, fav_id=teacher.id):
问题解决