Tarron Wescott, 22, of the 5400 block of Hadfield Street, was charged with endangering the welfare of a child and theft.
The boy is Wescott's stepson, police said.
Police were called to the Samuel Daroff School in West Philadelphia late Thursday afternoon after the 7-year-old found the gun.
Police say the boy notified school personnel after he found the weapon, believed to be a .38 caliber handgun. School officials then called police.
Police say the gun was loaded but jammed.
The principal of the school released the following statement:
During the afterschool program at Universal Daroff Charter School, a child was startled to learn that an unidentified item was in his book-bag and immediately alerted the afterschool teacher. Staff immediately took possession of the bag and followed the emergency procedure to secure the students and staff. The authorities were notified and arrived at the school and identified the item as a revolver and took over the investigation.
The Samuel Daroff School, located at 5630 Vine Street, is a charter school operated by Universal Companies.