request.user , by default is of type SimpleLazyObject . To solve this problem,
bookmark, created = Bookmark.objects.get_or_create( user = request.user, link = link )
it should be
bookmark, created = Bookmark.objects.get_or_create( user = request.user.id, link = link )
If this does not solve the problem, make sure you are logged in.
source share