He graduated at the prestigious Gorizia State Gymnasium in 1910 and entered the University of Vienna, where he studied medicine.
Danilo was the oldest of six children in a family which made its living through tanning, and which ran a small leather shop. Lokar did specialist work in Zagreb for a time before realizing that he could not work as a surgeon due to his poor health. As a consequence he decided to become a writer
In 1933 he published his first short story, "The Dance", in the progressive literary review Sodobnost.
During World World War II he was imprisoned by the Italian Fascist authorities in the concentration camp at Medea, in the Friul region. After the war he worked as a doctor until 1951, when he retired, fully dedicating his time to writing.
Lokar died in Ljubljana in 1989 and was buried in his hometown.