Get your taxes done using TurboTax

No the mortgage doesn't affect it.  It doesn't affect the Profit at all.  Just the net Proceeds.  Profit is Sales price minus Cost + improvements.  The mortgage is already part of the cost,