我一直收到以下错误:
'function' object has no attribute 'objects' for Like.
它存在于此视图中,我无法看到错误发生的原因。有什么帮助吗?
def Like(request, username, id):
""" User likes a project """
#message.success(request, "You've liked this project!")
# Get the username
user = get_object_or_404(User, username=username)
# Get the project
project = get_object_or_404(Project, id=id)
# Create the like
like = Like.objects.create(user=user.id, project=project.id)
return render_to_response('projects/liked.html')
答案 0 :(得分:7)
您已将视图函数调用为与模型相同,因此视图已在当前命名空间中覆盖名称“Like”。
如果你坚持PEP8命名约定,你总是给你的函数小写名称,所以这不会发生。