Our sympathies are with the rookie Spanish teacher at John Dewey HS in Gravesend who last week fell victim to a high-school freshman who snapped an up-skirt photo, then posted it to social media.

One Dewey staffer said, “A lot of teachers are concerned about the lifting of the ban” — that is, Mayor de Blasio’s lifting of the citywide ban on cellphones in schools.

Uh-uh. The mayor was right on that one. This incident doesn’t highlight the perils of letting kids bring cellphones to school. It highlights the fact that so many of our schools are barely under control.

Kids may use phones irresponsibly — but managing the classroom is the first duty of any teacher. Keeping order in the halls is the first job of school administrators.

And if city schools can’t handle kids with cellphones by setting and enforcing some basic rules, then best to find out now.

Because, under pressure from the feds, the city Department of Education is scrapping suspensions for “small” infractions like stealing or starting fights or doing drugs.

Instead, principals and staffs have been told to send the ruffians to . . . a talking circle called “restorative justice.” There, the poor little dears will be taught how to use their “feelings” to escape the consequences.

“Every reasonable effort must be made to correct student behavior through . . . restorative practices,” reads the city’s new 32-page discipline code.

The “logic” behind this lunacy is the idea that traditional discipline is racist because black students get suspended at higher rates than whites. Sorry: The main victims of the coming chaos in city schools will be the kids of all races who do want to learn.