Prior to Trump, has a US President ever explicitly denied being a racist?
Yes, Ronald Reagan frequently denied being racist.
Ben, if only it were possible to look into each other's hearts and minds, you would find no trace of prejudice or bigotry in mine.
Skinner, Kiron; Annelise Anderson, and Martin Anderson. Reagan: A Life in Letters. Simon and Schuster, 2004.
For a private example, in 1987 Reagan invited Supreme Court Justice Thurgood Marshall, who had called him a racist on TV, to the White House. After the event, Reagan wrote in his diaries that:
I'd asked for a meeting because of his public statement to Carl Rowan that I was a racist. I literally told him my life story & how there was not prejudice in me. I have examples of my relations with Minorities in school, as a sports announcer & as Gov. I think I made a friend.
Reagan, Ronald. The Reagan Diaries. Harper Collins, 2009.
We also have several eyewitness accounts from his presidency involving Reagan denying being racist in private conversations. For instance, Carl Rowan reports of a lunch with Reagan in 1988 during which the president said:
"Carl, I suggested this [meeting] when we were together [at the Gridiron dinner] because I had a feeling often that you didn't have the straight thing on me and racism and so forth . . . Carl, I was on the side of civil rights years before anyone ever used the term 'civil rights.'" I said I knew it couldn't be pleasing to have black leaders describe his administration as "eight years of disaster for the civil rights movement."
Rowan, Carl Thomas. Breaking barriers. Old Dominion University Academic Television Services, 1991.
As noted previously, Reagan made such denials frequently, both before and after his presidency. His autobiography provides a post-White House example:
As I've mentioned before, the myth about myself that has always bothered me the most is that i am a bigot who somehow surreptitiously condemns racial prejudice . . . Neither claim was true, and I think the record shows that.
Reagan, Ronald. An American Life: The Autobiography. Simon and Schuster, 1990.
Didn't search very far, but it looks like Bill Clinton did. He wasn't president anymore at the time though.
According to the ABC news article, Bill said:
There are things that I wished I urged her to do. Things I wished I had said, things I wished I hadn't said. But I am not a racist. I never made a racist comment and I did not attack him personally.
This happened after Hillary's unsuccessful campaign in 2008, during which he was accused of making some racially insensitive comments about Barack Obama. Below is the relevant part of the ABC article:
Clinton was referring to an uproar surrounding some of his comments in the South Carolina Democratic primary that prompted anger among some in the African-American community. After Obama, D-Ill., defeated his wife there, Clinton seemed to downplay the significance of the victory by noting Jesse Jackson had won South Carolina in 1984 and 1988, which some observers found offensive.
The controversy later brought an apology from Hillary Clinton, who told reporters, "You know, I am sorry if anyone was offended. It was certainly not meant in any way to be offensive."
EDIT: changed the source from the Sidney Morning Herald to ABC news, since the context is an interview to ABC news. The video is in the article, however it doesn't seem to be working, at least for me.