WASHINGTON — President Donald Trump revived some favorite campaign staples in a highly partisan speech to conservative activists Friday, including an anti-immigrant poem and a “lock her up” chant, unleashing himself after tense weeks that saw a school massacre, more White House turmoil and fresh indictments against campaign associates.

Speaking for well over an hour, clearly energized by the adulation of his audience, Trump nearly forgot to announce new sanctions against North Korea, which his staff had promoted as the major news of the event. After a couple lines about the penalties against 56 entities, he walked off the stage to the strains of “You Can’t Always Get What You Want,” the Rolling Stones song that closed his 2016 rallies.

Though his week had included emotional meetings with survivors and families of victims of the Parkland, Fla., shooting and past school massacres, Trump appeared buoyant before the Conservative Political Action Conference, a group he credits with launching his political career. He began by playfully reveling in his image on the convention center’s giant screens, pointing at his oversized projection and engaging in rare self-deprecating mockery of a bald spot.

“I try like hell to hide that bald spot, folks. I work hard at it!” Trump said. “Doesn’t look bad. Hey, we’re hanging in! Together, we’re hanging in.”

Then he indulged his crowd further, asking to their audible delight, “You don’t mind if I go off script a little bit, because it’s sort of boring?”

Trump did not ignore the 17 shooting victims. Despite their shared zeal for gun rights, the president gently prodded the hard-right audience to accept some modest and still unspecific changes to gun laws that he has talked about in recent days.

Those proposals — modest enough to get some buy-in from his allies at the National Rifle Association, a sponsor of the annual CPAC event — include enhanced background checks for gun purchasers and restrictions on gun ownership for people suffering from mental illness. Trump made an extensive pitch for his controversial, NRA-backed proposal to allow teachers and other trained school employees to carry guns.

“I’d rather have somebody that loves their students and wants to protect their students, than somebody who stands outside,” Trump said, a rebuke of the sheriff’s deputy assigned to the Parkland school who stayed outside during the shooting.

Guns were hardly Trump’s only topic in his rambling performance. He also blasted immigrants in the U.S. illegally, linked them to the epidemic of gun violence, and insisted he would build a southern border wall despite doubts from within his own administration.

Again berating Democrats, this time as advocates of illegal immigration, he said that they are “always fighting for the criminal. They’re not fighting for law-abiding citizens.”

As an allegory on immigrants, Trump read a poem called “The Snake” as he frequently did on the campaign trail — about a woman who cares for a wounded snake only to get killed when he attacks her.

“You knew damn well I was a snake before you took me in,” the snake proclaimed to the dying woman, in Trump’s telling.

Though immigration advocates and many others find the passage offensive, for Trump’s most loyal supporters, it is among his greatest hits.

The crowd broke into a chant of “Lock her up,” another staple of Trump campaign rallies, after Trump invoked Hillary Clinton — the “crooked candidate,” he called her, more than 15 months after voters cast their ballots.

Trump seemed happiest recounting his increasingly distant campaign. Yet again he boasted of his Electoral College vote count and mocked Clinton’s campaign strategy.

noah.bierman@latimes.com