In this paper, we consider how to express an Iwahori–Whittaker function through Demazure characters. Under some interesting combinatorial conditions, we obtain an explicit formula and thereby a generalization of the Casselman–Shalika formula. Under the same conditions, we compute the transition matrix between two natural bases for the space of Iwahori fixed vectors of an induced representation of a $p$-adic group; this corrects a result of Bump–Nakasuji.