Nancy Pelosi represents the left wing of the DEM party, not the voters in her district. The DEM party keeps her in power, not her voters.
If somebody ran against her in a primary, most of her support would come from the party: organizations not based in her district.
We live in a Party-ocracy, not a Democracy. Try running for office without the support of a party and see how far you get, even if you run in a primary.
Again, she represents the voters of her district quite well. Have you seen her district? Fruitcake centre.